queryParent()
The queryParent() function (client-side) sends general communication requests from the current window to the parent window that launched the script. For example, the parent window may be a SuiteCommerce web store or another ecommerce website.
Syntax
Use these syntax formats for the queryParent() function:
-
To pass a request object with some or all properties:
queryParent({ type: 'type', cmd: 'command', data: { x: 1, y: 2 } }).done(callback); -
To pass only the command parameter as a string:
queryParent('cmd').done(callback);
Return Value
The queryParent() function returns a promise that resolves to an object containing the response from the parent window.
Parameters
All properties are optional.
The queryParent() function accepts an object as a parameter. The object includes the following properties:
-
type(string) - Specifies the request type sent to the parent window. If omitted, this property defaults tons-cpq. -
cmd(string) - Specifies the task that the parent window should run. -
data(object) - Specifies additional data to send with the request.
Examples
The following examples show how to use the queryParent() function.
Retrieving User Profile Data Using the Complete Syntax
This example include both type and cmd as properties to retrieve user profile data from a SuiteCommerce web store. The parent window receives the request, runs the command, and returns the response to the callback.
queryParent({
type: 'ns-cpq',
cmd: 'get-user-profile'
}).done(function(data) {
console.log('Data', data);
});
Retrieving User Profile Data Using Command-Only Syntax
In this example, only the cmd property is sent in the request object. Because type is omitted, the function uses the default ns-cpq value. The callback receives the returned profile data in the same way as in the previous example.
queryParent({
cmd: 'get-user-profile'
}).done(function(data) {
console.log('Data', data);
});
Retrieving User Profile Data Using the Shortened String Syntax
This example passes only a string value, which queryParent() treats as the cmd property. This is the shortest syntax format and doesn't support sending additional request data. The response is handled in the callback like in the previous examples.
queryParent('get-user-profile').done(function(data) {
console.log('Data', data);
});