Writing XML value to Private Data in Script

Post Reply
matt.baile
Member
Posts: 43
Joined: Wed Nov 29, 2017 4:36 pm

Writing XML value to Private Data in Script

Post by matt.baile »

Hi guys, I need to set a Private Data variable based on the value contained in an XML file. I used the XML pickup and the value I want is IssueType (see below). I get an error when running this, so I'm not sure what's wrong. Keep in mind that both of the code snippets below are part of a larger script that's been in use for a long time. The script that both of these snippets are in is defining variables and creating an XML file based on the private data, hierarchy, etc. I jusst want to add a variable named IssueType based on the value in the XML pickup and then write it if it equals a certain value.

Code: Select all

	
var IssueType = job.getVariable()[Path="/JobSheet/IssueJobSheet/IssueInfo/@IssueType",Dataset="Xml",Model="XML"];
s.log(2, "Issue Type = " + IssueType);	



I then want to write the ISSUE_TYPE element into the XML file if the IssueType = Supplement. If not, I don't want to write the element at all.

Code: Select all

				
if((IssueType) == "Supplement"){
var iwNode = theDoc.createElement("ISSUE_TYPE");
var iwTextNode = theDoc.createText(IssueType);
iwNode.appendChild(iwTextNode);
theRootNode.appendChild(iwNode);}	

When a job hits this element,I get the following error: "Error in line 11 of script: TypeError. 'getVariable' undefined or not a function.
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: Writing XML value to Private Data in Script

Post by dkelly »

The correct syntax would be

Code: Select all

var IssueType = job.getVariableAsString( '[Path="/JobSheet/IssueJobSheet/IssueInfo/@IssueType",Dataset="Xml",Model="XML"]' );
matt.baile
Member
Posts: 43
Joined: Wed Nov 29, 2017 4:36 pm

Re: Writing XML value to Private Data in Script

Post by matt.baile »

Thanks for this.

I receive the following error when trying to write this:

Encountered unknown variable 'Path="/JobSheet/IssueJobSheet/IssueInfo/@IssueType"_Dataset="Xml"_Model="XML"' in 'SIX-XML_Text_r3'

I'm actually reading the XML path in another workflow on another server, but I'm packing the job and then unpacking it in the flow in question. I'm able to see the IssueType variable in the path when I mock-up something using single line text with variables, but it doesn't want to write it in the XML for some reason. The full code is below. You'll see my variable and then the writing of that variable under the //Matt Edit comments.

Code: Select all

function jobArrived( s : Switch, job : Job )
{
	{
	// Get job information		
	var jobName = job.getNameProper();
	var jobPath = job.getPath();
	var numPages = job.getVariableAsNumber("[Stats.NumberOfPages]");
	var iwColor = job.getHierarchyPath()[0];
	s.log(2, "Heirarchy Level 0 = " + iwColor);
	//Matt Edit
	var IssueType = job.getVariableAsString( '[Path="/JobSheet/IssueJobSheet/IssueInfo/@IssueType",Dataset="Xml",Model="XML"]' );

	// Create SIX XML subset document
	var theDoc = new Document();
				var theRootNode = theDoc.createElement("ISSUE_INNER_WORK_ITEM");
				theDoc.setDocumentElement(theRootNode);
					var theNewNode = theDoc.createElement("SEQUENCE_NUMBER");
					var theTextNode = theDoc.createText("1");
					theNewNode.appendChild(theTextNode);
					theRootNode.appendChild(theNewNode);
					var theNewNode = theDoc.createElement("ITEM_TYPE");
					var theTextNode = theDoc.createText("FULL");
					theNewNode.appendChild(theTextNode);
					theRootNode.appendChild(theNewNode);
					var theNewNode = theDoc.createElement("ITEM_FILE_NAME");
					var theTextNode = theDoc.createText(jobName + ".pdf");
					theNewNode.appendChild(theTextNode);
					theRootNode.appendChild(theNewNode);
					var theNewNode = theDoc.createElement("ITEM_PAGE_FIRST");
					var theTextNode = theDoc.createText("");
					theNewNode.appendChild(theTextNode);
					theRootNode.appendChild(theNewNode);
					var theNewNode = theDoc.createElement("ITEM_PAGE_LAST");
					var theTextNode = theDoc.createText("");
					theNewNode.appendChild(theTextNode);
					theRootNode.appendChild(theNewNode);
					if((iwColor) == "true" || (iwColor == "false")){
						var iwNode = theDoc.createElement("INNER_PAGE_COLOR");
						var iwTextNode = theDoc.createText(iwColor);
						iwNode.appendChild(iwTextNode);
						theRootNode.appendChild(iwNode);}					
					var theNewNode = theDoc.createElement("ITEM_NUMBER_OF_PAGES");
					var theTextNode = theDoc.createText(numPages);
					theNewNode.appendChild(theTextNode);
					theRootNode.appendChild(theNewNode);
					var theNewNode = theDoc.createElement("ITEM_NUMBER_OF_COLOR_PAGES");
					var theTextNode = theDoc.createText("0");
					theNewNode.appendChild(theTextNode);
					theRootNode.appendChild(theNewNode);
					//  Matt Edit
					if((IssueType) == "Supplement"){
						var iwNode = theDoc.createElement("ISSUE_TYPE");
						var iwTextNode = theDoc.createText(IssueType);
						iwNode.appendChild(iwTextNode);
						theRootNode.appendChild(iwNode);}					
		
			
	// Save document
	theDoc.save("C:/Users/dssuser/AppData/Roaming/Enfocus/Switch Server/backing/DigiPrint_Generic_r3/automanaged/Assemble/" + jobName + ".xml");
		{
		job.setPrivateData("numPages", (numPages));
		job.log(2, "Number of Text pages = " + numPages);
		}			
	}
job.sendToSingle(job.getPath());
}
matt.baile
Member
Posts: 43
Joined: Wed Nov 29, 2017 4:36 pm

Re: Writing XML value to Private Data in Script

Post by matt.baile »

I was missing a simple piece of the code: Metadata.Text

The code is now functioning perfectly:

Code: Select all

	var IssType = job.getVariableAsString( '[Metadata.Text:Path="/JobSheet/IssueJobSheet/IssueInfo/@IssueType",Dataset="Xml",Model="XML"]' );
Post Reply