1
0
-1

 

Hi,

I have a repeat block having field fname, lastname, middle name, address line1, address line2, city, zipcode, state. I want to pass the values to an service for each repeated values. How can I handle this requirement?

 

  1. Umakanta Dalai

    a sample example please how to push repeat data to service via action script and iterate over the array inside service?

CommentAdd your comment...

2 answers

  1.  
    2
    1
    0

    You can achieve this as follows:

    1. Add a data field (called 'Repeat JSON') that converts the repeat data to JSON format with a calculation rule:

      Util.jsonify(data.repeatData) 
    2. Add a Dynamic Data Button that calls your service and passes through the data field above as an input parameter.

      You should see data being passed to the service in the format:

       [ { "firstName": "Johny", "surname": "Lightning" }, { "firstName": "Tommy", "surname": "Thunder" } ]


       

    3. Code your groovy service to parse the repeatJson input parameter using the Path class as described here:
      Interrogating Structured Data Paths 

      String repeatJson = request.getParameter('repeatJson')?:'[]'
      Path p = new Path(repeatJson)
      p.paths('*').each {
          String firstName = it.val('firstName')
          String surname = it.val('surname')
          // Do something with this data
      }

     

    1. Umakanta Dalai

      I tried to access data of repeat block on click action of delete button. Its giving errors: "Form.convertToFieldDataMap required array input...".

      When i tried to debug in console log. the repeat content is giving value 'undefined'.

      console.log("repeatedContent: "+ data.repeatedContent ); //repeatedContent  is ID ref of repeat block.

      Please help with sample code for:

      1) how to fire an action on each delete/add button. So if i click on delete of a repeat item(say repeat item 2)the data of that particular repeat item should be saved via service to backend and the repeat would be deleted

      2) on click of continue button data should be saved via service to backend for all repeat items

       

      my sample form looks like below:

       

    2. Ben Warner

      Repeated Content is a standard container (block) so it makes sense that this has no value of its own. You should be referring to the Repeat Data element which is the actual repeat and has the repeat icon.

      If you are ever unsure about this, the type of the element is shown at the very top of the Properties panel:

    3. Umakanta Dalai

      Thanks Ben, i was pointing to the content block, my wrong.

      I tried as you suggested for repeat data

      console.log("repeatedContent: "+data.content1  ); still getting values 'undefined'.

       

       

      can you please help on below:

      1) how to fire an action on each delete/add button. So if i click on delete of a repeat item(say repeat item 2)the data of that particular repeat item should be saved via service to backend and the repeat would be deleted

      2) on click of continue button data should be saved via service to backend for all repeat items

       

    4. Ben Warner

      1) I would add a hidden dynamic data button to the repeat content and fire the click rule of this button in the click script of the delete button.

      2) You could add your logic to the click script of the Continue button but probably better to add a Page Change rule to the Page Controller to handle this.

    5. Umakanta Dalai

      sorry Ben.. I am a beginner to maestro. I am not clear how to implement both of your suggestions at this point. Will try and let you know. If there is any sample example for quick reference will be a great help.

    6. Ben Warner

      For repeating data there is a tutorial video here: All about repeating data

    CommentAdd your comment...
  2.  
    1
    0
    -1

    It depends in what format the service requires the data. Let's say your repeat has ID "myRepeat", you could pass "data.myRepeat" and you would get an array of objects, each of which had the field names with their original IDs, something like:

    [
      {fname: "Tim", lastName: "Stewart", addressLine1: "22 My Street", ...etc},
      {fname: "Umakanta", lastName: "Dalai", addressLine1: "33 Your Street", ...etc}
    ]

    If you need to change the field names, or include or exclude various fields, you need to look at using JavaScript map / sort / reduce etc. functions to transform your data.

    You can then pass the resulting data in a call to DynamicData.call() or you can use a datafield (or a reference to the original repeat data if it doesn't need any modification) within the field ref map of a Dynamic Data Button.

      CommentAdd your comment...