chanteldup

Update Repeating section XML in a Workflow

Blog Post created by chanteldup on Nov 7, 2018

So I came across a problem with updating repeating section XML and was not able to find any conclusive answer on previous posts or answered questions so decided to share it in the hope that it would help someone else. 

 

Scenario:
We are building a Purchase order system to be the middleman between the user/requestor, approver and SAP. in this process we are calling budget data from SAP by Line item, which works great but the moment you update XML it replaces values in all entries for the specified Xpath item, i.e. the budget value is overwritten for all lines in your repeating section everytime you loop through the next line item and check budget. 

 

In one question I saw a reply where the user was advised to use the Index value used in the For Each loop to find which line item to call, this however failed. Why? because my index default value is 0 and not 1... this means the first update is trying to update line 0 which does not exist.

 

Solution:

I then created a simple number variable with Default set to 1, and a Math Operation action to increment the counter at the end of each loop by 1, and Booyah! I could probably have changed the Index default value to 1 and still used that but as a standard my Indexes always have a default value of 0, plus it would be easier for the next person taking over maintenance on SharePoint and my workflows to figure out why I'm incrementing a counter, they might not realize my Index default is 1 and this could cause problems for them, we want to create solutions that are easy to hand over.

 

For those who do not know you need to connect your repeating section to a multiple lines Plain text field in your list, this makes working with the xml data in it much simpler. 

 

 

Once you've done this you have to write the Updated XML (which is stored in a Workflow variable of type Multiple Lines of text) back into your list column that your repeating section is connected to. This must be done inside the For Each loop:

 

Outcomes