Page 1 of 1

Variables in an XML location path

Posted: Fri Dec 14, 2018 3:09 pm
by RichardStemp
I'm trying to create a script to find the value of a PrivateDataKey and use it as a variable in an XML location path.
PrivateDataKey will be 01, 02, etc.
This is to get the value of /ItemOut[01], /ItemOut[02], etc.

Tried the below script, but getting error "error - no matching slot found"

var theVariable = job.getPrivateData("Original");
var xpathString = "[Metadata.TextIndexed:Path=\"/cXML/Request/OrderRequest/ItemOut[theVariable]/ItemID/SupplierPartAuxiliaryID\",Dataset=\"Xml\",Model=\"XML\"]";
var theValue = job.getVariableAsString(xpathString);

Can anyone tell me where I'm going wrong?

Once this is working I would like expand it by getting the ItemOut lineNumber value, so that I can rename the file going through a flow, with the value of Extrinsic "Filename".
No idea how to reference the 'lineNumber' value, though. (example XML below)

<ItemOut lineNumber="001" quantity="10000"><ItemDetail><Extrinsic name="section.General"><Extrinsic name="Filename">FILE_NAME.pdf</Extrinsic>

All hint and tips greatly appreciated.


Re: Variables in an XML location path

Posted: Mon Dec 17, 2018 7:45 am
by r.zegwaard
1st question:
Try this:

Code: Select all

var xpathString = "[Metadata.TextIndexed:Path=\"/cXML/Request/OrderRequest/ItemOut["+theVariable+"]/ItemID/SupplierPartAuxiliaryID\",Dataset=\"Xml\",Model=\"XML\"]";
You should open the XML-file and do a xpath-query to get the filename.

Code: Select all

// theValue -> the line-number to be found.
xmlDoc = new Document();
xmlRoot = xmDoc.getDocumentElement( );

filename = xmRoot.evalToString('//ItemOut[@lineNumber=" + theValue + "]/ItemDetail/Extrinsic[@name="Filename"]');
Didn't test it, so it might need a little tweaking... :-)

Notice the number of digits in the first (2) and second (3) part of your question.

Re: Variables in an XML location path

Posted: Fri Dec 28, 2018 2:44 pm
by RichardStemp
many thanks r.zegwaard :)

Re: Variables in an XML location path

Posted: Fri Feb 08, 2019 11:16 am
by RichardStemp

Eventually got the time to look at this topic again. Although parameters have changed slightly (like they do!).

Trying to get the below script to set a path segment on a Set Hierarchy element. The private data 'Part' brings through a number, so it can pick up the corresponding 'Part' node from XML passing through the flow. i.e. Part[1], Part[2], Part[3] etc.

Set Hierarchy, Path segment script-

Code: Select all

var thePart = job.getPrivateData("Part");
var xpathString = "[Metadata.Text:Path=\"/Job/Part['" + thePart + "']/PartName\",Dataset=\"Xml\",Model=\"XML\"]";
var theValue = job.getVariableAsString(xpathString);
Stripped-down sample XML-

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
Can only get the script to pull through the first instance of Job/Part/PartName that it finds, even though the Private Data passed to it is 1, 2, 3 etc.

No idea what I'm doing wrong.

All pointer and ideas greatly appreciated.
Thanks in advance :)