Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Execute Script - How to Update second node in XML group

Avatar

Former Community Member

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

Avatar

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

Avatar

Former Community Member

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?

Avatar

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

Avatar

Former Community Member

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....

Avatar

Level 10

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

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

Nith

Avatar

Former Community Member

Hi Nith,

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

Bizarre.

Thanks