Replace a String of Characters between a Start and End String

  • 9 January 2020
  • 5 replies
  • 5 views

Badge +7

Hello!

 

I'm looking to replace a random string back to blank for use in a repeating section.

For example I need this..

<SubTaskComments type="System.String">Some Comments</SubTaskComments>
<SubTaskComments type="System.String">Some more Comments</SubTaskComments>
<SubTaskComments type="System.String">Even more Comments</SubTaskComments>

 

To Be.. 

<SubTaskComments type="System.String"></SubTaskComments>
<SubTaskComments type="System.String"></SubTaskComments>
<SubTaskComments type="System.String"></SubTaskComments>

 

I'm doing this to reset a repeating section field back to a starting point without removing all of the data from the repeating section. I.E just the one column containing the comments.

 

Thanks for any help.

 

T.


5 replies

Badge +17

@Stonehage easiest way to do that would be to use the regular expression action. Use this pattern 

(?<=>).*(?=<)

to find the data between the two xml patterns and for each one it will extract it. You will have to do this as a loop to get all the comments out, but that shouldn't be difficult. You would use the replace and simply replace the text with nothing and it should return your original string empty. 

6099iA60580817C8A5E58.png

You can use the run now button to test the logic and see if your pattern returns what you want it to look like. Simply store than back into the variable then rebuild the XML as needed.

Badge +7

Thanks for that. I'm still struggling though. I think I needed to give more info..

 

This is my full xml example from one of my tasks...

 

<?xml version="1.0" encoding="utf-8"?><RepeaterData><Version /><Items><Item><SubTaskName type="System.String">Sub Task 1</SubTaskName><SubTaskOutcome type="System.String">Complete - No Issue</SubTaskOutcome><SubTaskComments type="System.String">Ok</SubTaskComments></Item><Item><SubTaskName type="System.String">Sub Task 2</SubTaskName><SubTaskOutcome type="System.String">Complete - No Issue</SubTaskOutcome><SubTaskComments type="System.String">Ok</SubTaskComments></Item><Item><SubTaskName type="System.String">Sub Task 3</SubTaskName><SubTaskOutcome type="System.String">Complete - No Issue</SubTaskOutcome><SubTaskComments type="System.String">Ok</SubTaskComments></Item><Item><SubTaskName type="System.String">Sub Task 4</SubTaskName><SubTaskOutcome type="System.String">Complete - Issue</SubTaskOutcome><SubTaskComments type="System.String">Ticket raised 2015464.</SubTaskComments></Item></Items></RepeaterData>

 

Which looks like this on my form.

 

6108i4E6E8A11BB1B1178.jpg

On completion of the task, a workflow archives the task to another list and I'm then trying to reset the answers but preserve the Sub Task names. I.E Back to...

 

6109iDDEC2BDC39D5625C.jpg

The Task outcome was simple. I just used replace. The comments are random hence my original question.

If I use the expression you gave it works on just the original sample but wipes the full xml.

 

T.

Badge +17

@Stonehage Any chance we can schedule a call to screenshare and walk through what you're doing? Here is a link to schedule some time with me - https://calendly.com/eric-harris. 

 

I think there may be a few easy processes to try here that may not need to wipe or reset that XML. 

Userlevel 6
Badge +22
Hi,

You could always use the update xml action to replace the specific nodes contents with blank.
Badge +7

So it was quite simple in the end...

 

6222iEA0F3AC8C78F0194.jpg

 

So no looping. Just a read and then an update.

 

Thanks for the help.

 

T.

Reply