1
0
-1
Hello,
How can I map arrays in the returned JSON from a dynamic data call to say a dropdown list or even a repeatable e.g. if the dynamic data call returns
{"EntityName": "YUM! RESTAURANTS AUSTRALIA PTY LIMITED", "BusinessNames": [{"OrganisationName": "DIAL A PIZZA"}, {"OrganisationName": "PIZZA HUT"}, {"OrganisationName": "PIZZA HUT AUSTRALIA"}, {"OrganisationName": "WING WORKS"}, {"OrganisationName": "YRI"}, {"OrganisationName": "YUM! RESTAURANTS INTERNATIONAL"}]}
how can I map the BusinessNames array tobe the contents of a dropdown list or even a repeatable block.

Thanks
  1. Jye Cusch
    Hi Thamba,

    I don't believe there is a way to directly map JSON dynamic data to dropdown lists or repeated blocks, but the same effect can be achieved using some scripting.

    For dropdown lists I'll refer you to the existing article on Populating Dropdown Lists.

    As for repeatable blocks the following javascript should achieve what you're after:

    //This data would come from the dynamic data service
    var jsondata = {"EntityName": "YUM! RESTAURANTS AUSTRALIA PTY LIMITED", "BusinessNames": [{"OrganisationName": "DIAL A PIZZA"}, {"OrganisationName": "PIZZA HUT"}, {"OrganisationName": "PIZZA HUT AUSTRALIA"}, {"OrganisationName": "WING WORKS"}, {"OrganisationName": "YRI"}, {"OrganisationName": "YUM! RESTAURANTS INTERNATIONAL"}]};
    //Remove all existing instances in the repeatable block
    {rpt_content}.setInstanceCount(0);
    //Iterate over the JSON data and create a new instance for each entry
    jsondata.BusinessNames.forEach(function(entry) {
    var newInstance = {rpt_content}.addInstance();
    //Assign 'OrganisationName' to the 'repeatfield'(a textfield) inside the new instance
    var newData = [
    {nodename:'repeatfield', value:entry.OrganisationName}
    ];
    //Assign the new values to the new instance
    sfc.updateChildNodeInformation(newInstance, newData);
    });

    note:'rpt_content' is the repeatable block and 'repeatfield' is a textfield inside that block.

  2. Thamba Pathmanathan
    Thanks Jye.

    Where do I put this script, and how do I get the JSON from the dynamic data service?
    Do I just place it in a button and call the servicee.g. https://industry.transactcentral.com/aba/servlet/FormDynamicDataServlet?ABN=16000674993&sfmRequestKey=xxx&sfmServiceName=ABR&sfmOperationName=dynamicData.
  3. Thamba Pathmanathan
    Thanks Jye,

    I went with the latter option. The first one wouldnt have worked as only one property in the returned JSON is an array. The rest are singular. It appears that you can only map to a repeatable if the whole JSON is an array. The only downside is that you cannot have test data, but that is a small price to pay.
CommentAdd your comment...

1 answer

  1.  
    1
    0
    -1
    1. Jye Cusch
      Sorry Thamba,

      It seems I was mistaken, it is in fact possible to map dynamic data JSON into repeatable blocks. The easiest way to do this is as follows:

      • Drag a 'Dynamic Data Assistant' into your form.

      • Select 'Repeatable Block' from the 'Please Select Result Block Type' dropdown.

      • Choose a title for the block.

      • Add fields to the result block.


      The dynamic data must be provided by a 'Dynamic Data' service on Transaction Manager, the service could act as a simple bridge retrieving JSON data from your existing service and forwarding it to the Composer form. To create this bridge follow the steps below:

      • Go to Transaction Manager > System > Service Definitions.

      • Click 'New Groovy Service' and choose 'Dynamic Data' as the service type.

      • Choose a name for the service and click 'Save' (remember the name, you'll need it in your Composer form).

      • Click the 'Service Parameters' tab for the newly created service.

      • Edit the 'groovyScript' parameter and replace the contents with the following line of code



      return 'https://industry.transactcentral.com/aba/servlet/FormDynamicDataServlet?ABN=16000674993&sfmRequestKey=64960d46d71cb9407fa09b257b3ca04f&sfmServiceName=ABR&sfmOperationName=dynamicData'.toURL().text


      • Save the service parameter and the dynamic data service should be ready to use.


      Now you can specify the dynamic data service name in your Composer form (but note that it won't work until the form is published to Manager)

      Alternatively, if you want direct access to the JSON returned by the dynamic data service you can use the following Composer JS function

      sfc.getDynamicDataFromJson(sourceNodeRef, serviceName, inputData, onSuccessNotify, onFailureNotify)

      For example you could put the following code in a button call 'btn_load' (or what ever you prefer).

      sfc.getDynamicDataFromJson({btn_load}, "Test Service", null,
      function(result) {
      //Success
      var jsonData = result.evtData.resultData;
      alert(jsonData.BusinessNames[0].OrganisationName);
      },

      function() {
      //Failure
      alert("failed");
      }
      );
    CommentAdd your comment...