Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Execute Script - How to Update second node in XML group

TGNZ1234
Level 3
Level 3

Hi,

I have an XML variable "myXML" which is set to:

<root>

     <nodes>

          <node>

               <value>a</value>

          </node>

          <node>

               <value>b</value>

          </node>

     </nodes>

</root>

Question - within an Execute script, how can I easily access and update the second node value? i.e. change "b" to "c"

The following fails in Execute Script (although it is possible using an XPath expression in a SetValue

  patExecContext.setProcessDataValue("/process_data/myXML/root/nodes/node[1]/value", "c");

If I have square brackets in this expression then it fails with a nasty error

Is there an easy way?

6 Replies
_Nith_
Level 10
Level 10

No need of ExecuteScript activity for this simple assignment.

You can try this XPATH expression:

and the value is "c"

Please note that the node index starts from 1,2 and so on.

Nith

TGNZ1234
Level 3
Level 3

Thanks Nith ...  I know I can do this with a SetValue.

But I need to do it inside an Execute Script call .. it's part of logic (loops, conditions etc), that are much too big and complex to use regular tasks in a process...

This is running in a script of 80 or so lines of code ....

Is it possible?

_Nith_
Level 10
Level 10

I tired your script in my sandbox and its working fine without fail.

I noticed an additional space in your xpath expression

Can you remove the space within node tag and try again?

Nith

TGNZ1234
Level 3
Level 3

Really?  Because I get a nasty error "Internal error"

It's not working at all on two systems.

And sorry, that pace was a copy / paste problem .. it's not in my code....

_Nith_
Level 10
Level 10

Share your email with me nith@mof.gov.bh

I will send your the process template to view the code.

Nith

TGNZ1234
Level 3
Level 3

Hi Nith,

I'll send you an e-mail now.  Strangley enough, I restarted the App Server and it's working.

Bizarre.

Thanks