Hi,
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);
theValue;
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.
Richard
Variables in an XML location path
-
- Newbie
- Posts: 17
- Joined: Tue Jul 21, 2015 2:58 pm
-
- Member
- Posts: 94
- Joined: Fri Jul 08, 2011 10:31 am
- Location: The Netherlands
Re: Variables in an XML location path
1st question:
Try this:
2nd:
You should open the XML-file and do a xpath-query to get the 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.
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"]');
Notice the number of digits in the first (2) and second (3) part of your question.
-
- Newbie
- Posts: 17
- Joined: Tue Jul 21, 2015 2:58 pm
Re: Variables in an XML location path
many thanks r.zegwaard
-
- Newbie
- Posts: 17
- Joined: Tue Jul 21, 2015 2:58 pm
Re: Variables in an XML location path
Hi
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-
Stripped-down sample XML-
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
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);
theValue;
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<Job>
<NoOfParts>2</NoOfParts>
<Part>
<PartName>Cover</PartName>
<PartPages>4</PartPages>
</Part>
<Part>
<PartName>Text</PartName>
<PartPages>16</PartPages>
</Part>
</Job>
No idea what I'm doing wrong.
All pointer and ideas greatly appreciated.
Thanks in advance