Expand my Community achievements bar.

SOLVED

Updating XML Additional Data for a Seed Address

Avatar

Level 1

Hi all,

 

I would like to ask for some assistance with the following.

Lets assume that an existing Seed address has the below XML data present inside the Additional Data tab

 

vavasol_0-1683731594218.png

 

 

Using a Javascript activity inside a workflow, i'm able to retrieve the value of attribute "attribute_1" and log it successfully in the workflow log.

 

var seed = nms.seedMember.load(My_Test_Seed); //load the seed address record
logInfo(seed.targetData.testData.@attribute_1); //This logs the value "Yes" fine in the workflow log
seed.save(); //save the seed address record

 

What i'm looking to be able to do, again using a Javascript inside a workflow, is to be able to update the value of attribute_1 to "No".

I tried something simple like the below but it doesn't work:

 

var seed = nms.seedMember.load(My_Test_Seed);

seed.targetData.testData.@attribute_1 = "No" //Update value to "No" - This does not work

seed.save(); //save the seed address record

 

Even though the script doesn't through any errors or anything, the value does not update. Anyone has any ideas or knows if/how its possible to achieve this? If its possible, i'm assuming maybe it needs some XML parsing or something, but i'm not sure (not really too familiar with XML in general)

 

Any assistance appreciated.

 

Regards

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @vavasol,

Firstly, your xml has two elements with the same name "testData". You might want to club them into one, with two different attributes.

The following script should update the attribute value.

var seed = nms.seedMember.load(Your_seed_id).toDocument(); //load the seed address record
seed.getElementsByTagName("testData")[0].setAttribute("attribute_1","No");
seed.root.setAttribute("xtkschema","nms:seedMember");
seed.root.setAttribute("_operation","update");
xtk.session.Write(seed); //save the seed address record


View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @vavasol,

Firstly, your xml has two elements with the same name "testData". You might want to club them into one, with two different attributes.

The following script should update the attribute value.

var seed = nms.seedMember.load(Your_seed_id).toDocument(); //load the seed address record
seed.getElementsByTagName("testData")[0].setAttribute("attribute_1","No");
seed.root.setAttribute("xtkschema","nms:seedMember");
seed.root.setAttribute("_operation","update");
xtk.session.Write(seed); //save the seed address record