Posting Array of Objects to Web Service
Canvas now enables you to post array of objects to a web service in a simple and efficient way. With subtle configurations, you can post the array of objects to a web service, thereby facilitating the means of posting the data to a web service in an effective way.
In the following example, a web service data source is created for posting the array of objects to a web service. The array of objects need to be specified for posting the data to the web service. Before creating dynamic child records in Request Modeler, it is essential to specify the appropriate array of objects while configuring the web service data source in Sigma Studio. To post the array of objects to a web service, perform the following steps in Sigma Studio:
Let's assume that a web service connection has already been created in Sigma Studio. For detailed information on creating a web service connection, refer Creating a Web Service Connection.
- In the Connections list, right-click the existing web service connection and select the Create Data Source option.
The Create New Data Source screen appears. - Enter a unique name in the Data Source Name field, e.g. POST WEB SERVICE DS.
- Enter the appropriate relative part of the web service URL in the Relative part of the URL field, e.g. publisher/AutoFunding.
- Click the Communication App ID drop-down list and select the REST POST JSON Gateway option.
Click the Upload JSON option to upload the appropriate JSON file, e.g. Details.json.
{ "Response": { "chargeCurrencyCode": "USD", "CommissionAmount": "1", "TotalCreditAmount": "10", "StatusDescription": "SUCCESS", "serviceTaxAmount": "0", "StatusCode": "0", "TotalDebitAmount": "10" } }
- Specify the appropriate column root in the Column Root field, e.g. $.Response.
- In the JSON Configuration, categorized under Request JSON Configuration, click theicon, on the extreme right side of the Object tab to create a new object.
Type the appropriate array name in the Name field, e.g. record.
For an array, the suffix $form should be added to the array Name, e.g. record$form.
- Click the Text drop-down list and select the Array option.
- Proceed to click Add.
- Proceed to click Add.
- Hover the mouse on the extreme right side of the newly created array and click icon to add a new object.
- Click the Text drop-down list and select the Object option.
- To add the object, click Add.
- Hover the mouse on the extreme right side of the newly created object and clickicon to add a new object.
- Provide the appropriate key in the Name field, e.g. accountNumber.
- Enter an appropriate value in the Value field, e.g. $form.accountNumber.
The value should be mandatorily provided as $form.<Value> in the Value field, e.g. $form.accountNumber.
- To add the object, click Add.
- To save the web service data source, click Save.
A confirmation message, indicating the successful creation of web service data source, appears. - Click Ok.
After successfully creating the web service data source, proceed to create a request for the web service using Request Modeler in Sigma Studio. For detailed information on creating a request, refer Configuring Request Modeler and Creating Library Request.
On successfully creating the request, a form gets created automatically and the form can be viewed in the Form Definition List, with the provided Request ID serving as the Form ID.
To pass the array of values in the form's listener file, specify the array of values, as shown in the following code snippet:
The key "accountNumber" should be similar to the key, provided during the creation of web service data source. The suffix _T1 should be added to the Request Model ID in the form model, associated with the Request Modeler forms. The following code snippet serves as a sample reference:
fm.model.setValue("<REQ_MODEL_ID>_T1",arr); //To set the array of objects in the form model
canvas.form.listeners.ReqForm = Class(canvas.Observable, { constructor: function(config) { this.fm = config.fm; }, registerHandlers: function() { this.fm.registerHandler(CFEC.CLICK, 'SUBMIT', function(fm, event, fieldName, value) { var arrObj = [{ "accountNumber": "000100000100003" }, { "accountNumber": "0001000001006767" }, { "accountNumber": "000100000105757" }, { "accountNumber": "0001000001005425" }, { "accountNumber": "00010000010245245" }, { "accountNumber": "0001000001045252" }, { "accountNumber": "000100000100567572" }, { "accountNumber": "000100000153454302" }]; fm.model.setValue("ACCOUNTDETAILS_T1",arrObj); //ACCOUNTDETAILS is the Request Model ID canvas.modeler.executeAction(fm,"SUBMIT"); }); } }); CFLR.registerListener("ACCOUNT_DETAILS_FORM", canvas.form.listeners.ReqForm);
Copyright © Intellect Design Arena Limited.
All rights reserved. These materials are confidential and proprietary to Intellect Design Arena Limited and no part of these materials should be reproduced, published in any form by any means, electronic or mechanical including photocopy or any information storage or retrieval system nor should the materials be disclosed to third parties without the express written authorization of Intellect Design Arena Limited.