Page 1 of 1

inject job

Posted: Wed Feb 26, 2020 1:36 am
by danb
Given:
var XMLData = job.getDataset("Xml");
var itemToInject = 2
var doIT = XMLData.evalToString("/Documents/Document[" + itemToInject + "]/filePath");
doIT;

This works and injects document 2 of a 3 document xml.
My question is how do I iterate through the xml to get all three documents injected?

thanks

Re: inject job

Posted: Wed Feb 26, 2020 9:52 am
by laurentd
Variable XPath Repeater app does the job:
https://www.enfocus.com/en/appstore/pro ... able-xpath

Re: inject job

Posted: Wed Mar 04, 2020 12:37 am
by danb
that's no fun at all. i'll post here once i've figured it out.

Re: inject job

Posted: Wed Mar 04, 2020 4:22 am
by danb
//set private data
loop=[Metadata.Integer:Path="count(/Documents/Document)",Dataset="Xml",Model="XML"]

//then repeat loop calculation
loop=[Switch.Calculation:Expression="[Job.PrivateData:Key="loop"]-1"]

//then inject job, job path script expression
var XMLData = job.getDataset("Xml");
var x = job.getPrivateData("loop");
var externalID = XMLData.evalToString("/Documents/Document[" + x + "]/filePath");
job.log(2, externalID);
externalID;

//BOOM!

Re: inject job

Posted: Wed Mar 04, 2020 4:25 am
by danb
now for further refinements how can I get this all done in the script expression?

Re: inject job

Posted: Tue Mar 31, 2020 7:56 am
by Sunnyland
Can you do it with a loop?

If I have understood what you are trying to do correctly.
This could work for you.

var dataset = job.getDataset("Xml");
var xml = new Document(dataset.getPath());

var doc = xml.evalToNodes("/Documents/Document");

for(var x=1; x<doc.length+1;x++){
var externalID = XMLData.evalToString("/Documents/Document[" + x + "]/filePath");
job.log(2, externalID);
externalID;
}