1
0
-1

how to read the value of a data field so that i can hide and show other fields based on values of data field?

for example: i have a data field mapped to City. The values is returned from groovy by DDS call. if i have 2 city names in data field, i want to display a dropdown and if 1 city name returned from DDS, want to display in text field.

    CommentAdd your comment...

    3 answers

    1.  
      1
      0
      -1

      If your data field contains JSON data then you can use JSON.parse to convert to object.

      https://www.w3schools.com/js/js_json_parse.asp

      1. Umakanta Dalai

        Thanks Ben, this will help, will give try

      CommentAdd your comment...
    2.  
      2
      1
      0

      Hi Umakanta,

      If you use the Maestro DynamicData.call() API function in a rule, like a field change or page load, you can assign the response to a single data field like this:

      DynamicData API Call
      var params = {};
      params.paramName = data.dataField;
      DynamicData.call("Transact DDS Service Name", params).then(function(response){
      	data.response = response;
      }
       

      Because Maestro understands the nature of the Dynamic Data Service call, it automatically serializes the response from Transact Manager into an object.  This is particularly useful for complex structures with nested hierarchies and arrays.

      Next, in the Show If... visibility rules for the target fields, the text field and the dropdown list in your case, you simply add a test for the array of returned cities:

      Textbox Show If...
      // this logical test will return true, making the field visible in  Show If...
      data.response.cities.length == 1
      Dropdown Show If...
      // this logical test will return true, making the field visible in  Show If...
      data.response.cities.length > 1

       

      Here I'm assuming that the data that came back from Transaction Manager looks like:

      Sample data structure
      {
      	"cities": [
      		"San Diego",
      		"San Jose"
      	]
      }

       

      One feature that I really like, is the ability to mock up data in Maestro, by simply returning the data I expect from the calculation rule of my response data field.  This allows me to continue developing, or build a model that I expect from the Dynamic Data call.

      Response data field mock up
      return {
      	"cities": [
      		"San Diego",
      		"San Jose"
      	]
      }

      You should read Ben's Advanced Debugging of Maestro Forms to guide your development.

      1. umakanta dalai

        Thanks Jason, this example is a great one.

        However implementing this my form throws multiple unknown error on page load, because by that time the DDS is not called

      2. Jason Hendry

        Hi Umakanta,

        You raise a good point.  In my examples, there should be guards around the use of the data.response fields in the dropdown and textbox Show If... rules.

      CommentAdd your comment...
    3.  
      1
      0
      -1

      In the script editor for your visibility rule you can double click the data field in the heirachy to add its value to your logic.

      1. Umakanta Dalai

        Sorry Ben,I think I couldnt address my requirement properly.

        my Data Field contain 2 cities(json result retun from DDS) say, [San Diego] [San Jose]

        How can I read these values of 'data field' so i cant count 2 ?

      CommentAdd your comment...