Can you Modify Subform data, not just use it inside a loop?

Comments

13 comments

  • Avatar
    Karl Makatenas

    How are you using the array indexing variable?  I know :[this] won't work because there's no direct reference to the "this" variable outside of the form, so have you tried :[${/pd:AP/pd:processFields/stuff}] or is that not overwriting the data?  I remember this being a chore to figure out the last time I messed with it and never came to a conclusion because we figured out a way to work with the data sans modification.

  • Avatar
    Loren Bratzler

    I have run into this issue as well where I would like to be able to update repeating data in a loop.  In fact, I even created a little test application to try to accomplish this but was never able to get it to work.

    I know that if you go into the Process Monitor / Data tab and look at the XPath for a repeating element, you will see an index in brackets that appears right after the "repeating" node of the path:

    /pd:AP/pd:formFields/pd:SubForm1_SubForm/pd:SubForm1[1]/pd:TextBox1

    So it stands to reason that you should be able to define an index variable in your processFields that you initialize to zero before starting the loop.  Then within each iteration of the loop, you increment the index variable by 1.  Then you just need to update the current entry with the new value by indexing it with your index variable.  Of course, to do that, you can't just drag-n-drop the field from the schema to the Process Variable field since it won't have any indexing.  So I tried to hard-code the field with index like this:

    /pd:AP/pd:formFields/pd:SubForm1_SubForm/pd:SubForm1[/pd:AP/pd:processFields/pd:LoopIndex]/pd:TextBox1

    But what happens is that it only updates the first entry in the repeating element.  So for example, if you have 3 entries in your sub-form, the first occurrence gets updated with what you intended to update in occurrence 3 while occurrences 2 and 3 do not get updated at all.

    Here is a link to my Test Application:

    Test Update Loop

    If anyone can figure out how to make this work I am sure a lot of people could benefit from it.

    AgilePoint needs to consider creating an activity for doing this or enhancing the "Update Process Data" activity to be able to do some kind of indexing for repeating elements.

     

  • Avatar
    Karl Makatenas

    So the best alternative I could come up with in a reasonable amount of time is to export all the data to another data source, then read the data back into the repeatable section.

    In my example, I looped through all the data, made modifications to each row while putting the row in SharePoint, and pulled the data back via a CAML query.  It works, but it's obviously not my first choice.

    It seems the issue exists because I can't further nest process variables into the left side of the Update Process Data activity due to the way the C# seems to parse, so I can't save back data to particular array indices.  I can read data from specific array indices, though.

  • Avatar
    Karl Makatenas

    The documentation seems to hint that we can change repeatable data, so now I'm curious about the syntax:

    Process Data Variable

    Accepted Values:
    • An Xpath to an XML schema element.
    • At runtime, if the schema element does not exist, the process ignores the action. If you want to change a repeatable XML element, make sure it exists in the schema.

    https://documentation.agilepoint.com/00/appbuilder/cloudenvInstructionsUpdateCustomAttributes.html 

  • Avatar
    Nik

    The subform can be modified by JS as long as it is on the form. (Can stay hidden)

    We are modifying a unique ID, to ensure it is unique before writing it to a SQL database table via Data Population. 

    Edit: Our code was developed jointly with professional services so I do not know if I can/should share it directly here. 

  • Avatar
    MikeM

    Yes, we are modifying repeating data inside a form with JS as well.  The documentation AgilePoint provides is quite good in that regard, albeit that adding extra rows is very slow. 

    I am really wondering how we might be able to do it outside a form, with the Update Process Shape or similar. 

  • Avatar
    Karl Makatenas

    This use case seems to hint that the form is already submitted, so the data has to be edited within the process (outside of the form).  Inside the form is relatively easy with JS.  I still don't have any other options than the SharePoint bulk upload to a CAML query download mentioned above.

  • Avatar
    Matthias

    I have exactly the same issue as Loren.

            pd:SubForm1[1]/pd:Name  ===>  pd:SubForm1[/pd:AP/pd:processFields/pd:LoopIndex]/pd:Name

    I want to replace the number in the brackets with a index variable.

     

    Does everyone have a solution in the meantime?

    Thanks in advance

     

     

  • Avatar
    Mario Oenning

    Yes you can do this with an update process data shape (with some dirty hack):

     

    /pd:AP/pd:formFields/pd:SubForm2_SubForm/pd:SubForm2[" + ds["/pd:AP/pd:processFields/pd:LoopCount"] + "]/pd:SubProcess

     

    btw. everything you enter there is transformed to c# code (which you can see when you press the validation button). you can do all kind of crazy things with it:

  • Avatar
    Loren Bratzler

    Mario,

    Thanks for this tip.  I just tried it in my little test application and it worked like a charm.  The loop was able to update the repeating elements of the existing subform data:

    I'm not sure I quite understand what you are doing in the target variable section of the Update Process Data activity with the quotation marks and the characters enclosed within them:

    Can you explain what this is doing?

    Another question I would have is can this same approach (or something similar) be used to add new elements to repeating data?

  • Avatar
    Mario Oenning

    Hi,

    you can see which code is generated when you use a field and drag it into the variable screen from your form fields.

    F.e. in this case there is a form field "test" which has been used.

    See that the field test is basically translated to /pd:AP/pd:formFields/pd:test in the code.

    Since you can write your own string into the field you could do:

     

    which works exactly the same way:

     

    So you just build your own string:

    "/pd:AP/pd:formFields/pd:SubForm2_SubForm/pd:SubForm2["

    + ds["/pd:AP/pd:processFields/pd:LoopCount"]

    + "]/pd:SubProcess"

     

    Note that ds["/pd:AP/pd:processFields/pd:LoopCount"] evaluates to whatever the value of your LoopCount varibale currently is.

    which means for example:

     

    "/pd:AP/pd:formFields/pd:SubForm2_SubForm/pd:SubForm2["

    + "2"

    + "]/pd:SubProcess"

     

    which makes it:

    "/pd:AP/pd:formFields/pd:SubForm2_SubForm/pd:SubForm2[2]/pd:SubProcess"

    (note that the first and last quotation marks need to be removed since those are added when the code is generated)

     

    regarding "adding new elements": Don't know, I've never tried it actually. Just give it a try...

     

  • Avatar
    Loren Bratzler

    So ds and dsNew are really just variable names of type WFCustomAttributes ?

    And I did try to modify my test app to add new entries to the repeating element structure but it did not work!

  • Avatar
    Mario Oenning

    yepp

Please sign in to leave a comment.