Passing original metadata to a new job within a script

Post Reply
jugganaut
Member
Posts: 39
Joined: Wed May 08, 2013 6:48 pm

Passing original metadata to a new job within a script

Post by jugganaut »

I'm creating a new XML(PPML) file from ingested meta data via XML Pickup with a Javascript in SwitchScripter. I'm treating the original XML file as an asset and passing it onto the script to invoke it. My issue is that I'd like to maintain some or all of the original meta data in the new XML(PPML) file that I am creating.



Right now I'm using:





var ppmlOut = s.createNewJob();

ppmlOut.sendToSingle(ppmlPath);





to output the new file, but obviously I'm creating a new job to do it.


User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Passing original metadata to a new job within a script

Post by gabrielp »

Gotta admit dude, having a bit of a brain-fart while reading that. But I think what would solve your problem would be to write the metadata out as a dataset and then set that dataset on the new job you're creating.



Not my finest work -- there's probably a much better way of doing this:

// Throw the XML in a soap object since its easy to transfer into a data set

var response = new SOAP();

response.setBody(XmlTotal);

job.log(2, 'set soap body');

// Make a temp file for the response and request

var request_temp_file = job.createPathWithName( job.getNameProper() + '_request.xml' );

// Write XML to temp files

response.writeToFile( request_temp_file );

job.log(2, 'make temp file');

// New data set

var responseDataset = job.createDataset('XML');

// Get path of the file I need to build

var responseDatasetPath = responseDataset.getPath();

// Create new file with dataset path

var datasetResponseFile = new File( responseDatasetPath );

// Write to data set file

response.writeToFile( datasetResponseFile.fullName );

// Set datasets

job.setDataset(datasetName, responseDataset);

job.log(2, 'set data sets');

But... before you go this route, might want to spend a little time thinking why you need to do this, as it doesn't seem clear to me that there isn't a better way. I'd ask, why does your XML file need to be the asset you're moving along? It's redundant to have the data in the asset itself and as metadata. If you don't have an asset to pass along or to consume the XML file into, then you could do an Inject Job with a dummy file.
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
jugganaut
Member
Posts: 39
Joined: Wed May 08, 2013 6:48 pm

Passing original metadata to a new job within a script

Post by jugganaut »

Man, I had a great response all typed out that made sense with my early morning toddler head... I'll try again to type it all out.



The basic idea is that I have a series of XML files that I need to turn into PPML files, which is still basic XML. I would have used XSLT, but I needed to do some calculations based on the incoming metadata from the original XML, so I figured writing a script would be easier.



The basic flow is as follows:



XML is input into the flow, passes into an XML pickup element as an asset. The XML is then passed onto a script that takes in some of the metadata to create some variables to make calculations to put into the PPML file. The PPML file is created in a temp folder, then switch creates a new job to pass the PPML file out of the temp folder and into the next element in the flow.



I'd like to use some of the original metadata from the XML file later on in the flow, but it doesn't look like I can just put it into the PPML file and pull it back out later - that's more of a format issue with PPML than anything to do with Switch.



So the question is: how can I pass the original metadata onto the newly created job that is needed to push the new PPML file into the next flow element.



OR, how can I use the same job?



I'm still getting wrapping my head around the Switch functions, classes, etc - so the answer is likely much easier than it appears. Simply put, I need to pass the newly created file into the original job....
jugganaut
Member
Posts: 39
Joined: Wed May 08, 2013 6:48 pm

Passing original metadata to a new job within a script

Post by jugganaut »

Like I said, I knew it was an easy answer and I finally figured it out. I just used:





job.sendToSingle(ppmlPath);





Makes sense now.
User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Passing original metadata to a new job within a script

Post by gabrielp »

jugganaut wrote: Simply put, I need to pass the newly created file into the original job....
Simplest solution would be to use write() (~pg 106 in Switch 12 scripting guide) to overwrite the contents of the job with the new contents of your PPML file. That way, you wouldn't create a new job and all of your metadata/privatedata would be intact. I think that might be incorrect in light of your update.



jugganaut wrote: So the question is: how can I pass the original metadata onto the newly created job that is needed to push the new PPML file into the next flow element.


If you want to go this route, just write the metadata to a dataset and then set that dataset to the new job. Pretty much, the code example I have above. But you would have to pull out each dataset unless you only wanted to add the dataset that existed in the XML file (I think privateData is it's own dataset, for example).



jugganaut wrote: XML is input into the flow, passes into an XML pickup element as an asset. The XML is then passed onto a script that takes in some of the metadata to create some variables to make calculations to put into the PPML file. The PPML file is created in a temp folder, then switch creates a new job to pass the PPML file out of the temp folder and into the next element in the flow.



I'd like to use some of the original metadata from the XML file later on in the flow, but it doesn't look like I can just put it into the PPML file and pull it back out later - that's more of a format issue with PPML than anything to do with Switch.


So essentially, you're looking to convert your input XML to PPML (making a few changes along the way). I don't know much (anything actually) about PPML. Maybe someone else here might know a cleaner way to do that.
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
jugganaut
Member
Posts: 39
Joined: Wed May 08, 2013 6:48 pm

Passing original metadata to a new job within a script

Post by jugganaut »

Thanks a bunch for the replies.



And I did use write(); create the new file...



To recap, instead of passing the metadata on to a new job, I simply output the newly created file into the original job. The XML gets trashed, so there's only one file that is output.


Post Reply