using metadata in a new file

Post Reply
abonsey
Member
Posts: 98
Joined: Fri May 24, 2013 5:10 pm

using metadata in a new file

Post by abonsey »

I have a JDF (created via the HP JDF Control configurator) that has a dataset attached to it.
I'm trying to create a simple text file for use elsewhere but I keep getting the error:

Error in line 11 of script : TypeError. 'ToString' undefined or not a function
Invalid XML document


Below is the script. Can anybody see what I've done wrong??


function jobArrived( s : Switch, job : Job )

{
var dataset = job.getDataset("XML");
var xml = new Document(dataset);
var JobCode = dataset.ToString("/Job/@JobCode")



var textFile = new File(s.createPathWithName(JobCode));
textFile.open(File.WriteOnly);

textFile.writeLine("Add to Digital");
textFile.writeLine("Indigo");

textFile.close();

job.sendToSingle(textFile);
job.sendToSingle(textFile.fullName);

}

Thanks
Andrew
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

Re: using metadata in a new file

Post by freddyp »

Code: Select all

var dataset = job.getDataset("XML");
So far, so good.

Code: Select all

var xml = new Document(dataset);
To load an XML document you have to specify the path to the XML document, but you are using the Dataset object returned by getDataset as is. You have to use the backing file of the dataset: dataset.getPath( );

Code: Select all

var JobCode = dataset.ToString("/Job/@JobCode")
There are several functions for evaluating XPaths, but the one you need is evalToString. The function evalToString function also has to be done on the XML object, not on the Dataset object. And there should be a semicolon at the end of the line. The correct line is:

Code: Select all

var JobCode = xml.evalToString("/Job/@JobCode");
abonsey
Member
Posts: 98
Joined: Fri May 24, 2013 5:10 pm

Re: using metadata in a new file

Post by abonsey »

Hi Freddy,
Thanks for that, but I must be missing it still as the changes still error. Here's what I've got:

var dataset = job.getDataset("XML");
var xml = new Document(dataset.getPath());
var JobCode = xml.evalToString("/Job/@JobCode");


var textFile = new File(s.createPathWithName(JobCode));


I still get the same error
Error in line 11 of script : TypeError. Undefined member function 'ToString' for object 'undefined' of type: 'Undefined'


Any ideas
Andrew
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

Re: using metadata in a new file

Post by freddyp »

As I do not know which of the lines is line 11 it is hard to say anything conclusive.

Are you sure the name of the dataset is "XML"? Add

Code: Select all

s.log(1,dataset);
after the line where you initialize the dataset variable to see if what you get is a Dataset object or undefined. My guess is that you get undefined in which case xml will also be undefined and evalToString does not work. But you should see other errors as well as the XML file cannot be loaded.

Are you testing this in Switch Scripter or in a flow? When in a flow, do not forget to stop and start the flow again or your changes are not taken into account.
abonsey
Member
Posts: 98
Joined: Fri May 24, 2013 5:10 pm

Re: using metadata in a new file

Post by abonsey »

I checked the dataset name and it is "XML".
After adding in the log command I get a warning about an invalid XML document.

I decide to export the XML to a new dataset and get the script to read that newly created dataset but it still errors.
All this is done within the flow and it is being stopped/started each time
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

Re: using metadata in a new file

Post by freddyp »

Then you should investigate if the dataset with the name "XML" is actually an XML file. Go to the application data root folder (you find the path in the Preferences) and based on the time of the file you should be able to find the dataset backing file quite easily in the folder "datasets".

How is the dataset added?
abonsey
Member
Posts: 98
Joined: Fri May 24, 2013 5:10 pm

Re: using metadata in a new file- SOLVED

Post by abonsey »

All working fine now. The amends to the script didn't take in the flow even after stop starting... came back to it an our later and it all processed OK with no further changes.

No on to something new :)
Post Reply