Page 1 of 1
How to create a Dataset using a script?
Posted: Wed Jan 25, 2012 11:24 am
by reprokaiser
Hi All,
I'm trying to create an external dataset (just like the ones created by a Submit Point, or an XML Pickup tool). In the manual it is repeatedly stated that an external dataset can't be altered, but it's possible to create a new one.
I'm able to construct and save an XML document, then I can pick it up with the appropriate tool in a flow. But how can I do that in one step, using a script? I see that there are certain commands to create a dataset, but I can't do anything more with that. How can I build up a Dataset, or associate a Document with a Dataset?
Any help appreciated.
Peter,
Budapest
How to create a Dataset using a script?
Posted: Wed Jan 25, 2012 4:08 pm
by Evan
Hi reprokaise,
I have often to use this one. This is the script I use. I use it inside SwitchScripter. Unfortunately, we cant insert file and it seems not possible to join a specific member. If you give me a link I can send you the file so you will just need to import it via Script Element.
function jobArrived( s : Switch, job : Job )
{
var TextToAdd = s.getPropertyValue("EnterTextToAdd");
var NameOfPrivateData = s.getPropertyValue("PrivateDataKey");
var InputJob = job.getPath();
job.setPrivateData( NameOfPrivateData, TextToAdd );
job.sendToSingle(InputJob);
}
How to create a Dataset using a script?
Posted: Thu Jan 26, 2012 7:57 am
by rzacherl
Hi Peter,
that's a four steps process:
1. create a new generic XML based dataset with help of the createDataset() method of the Job class
2. create a new XML by using the appropriate classes and methods of the XML module.
3. save the new XML file under the path of the newly created generic dataset returned by the getPath() method of the Dataset class. This way you overwrite the empty dataset file created in step 1 with the contents of your newly created XML file
4. assign the new XML based dataset to the specific job instance via the setDataset() method of the Job class.
Regards,
Robert
How to create a Dataset using a script?
Posted: Thu Jan 26, 2012 3:43 pm
by reprokaiser
Hi Robert,
thanks for the help! I figured it out and the solution is up and running now. It's incredible what can be done by scripting Switch.
Kind regards,
Peter
How to create a Dataset using a script?
Posted: Thu Jan 26, 2012 3:47 pm
by dkelly
This Javascript creates a simple XML dataset and assigns it to the current job.
var theXML = new Document();
// create the root node
var rootElem = theXML.createElement( "SampleXML", null );
theXML.appendChild( rootElem );
// create the first child node
var theChildNode = theXML.createElement( "ChildNode", null );
rootElem.appendChild( theChildNode );
var theValue = theXML.createText( "TextValue" ); // set value
theChildNode.appendChild( theValue );
theChildNode.addAttribute( "a", null, "yes"); // add attribute
// save the XML document
var theDataset = job.createDataset("XML");
var theXMLFilename = theDataset.getPath();
theXML.save(theXMLFilename);
job.setDataset("sampleXML", theDataset);
delete theXML;
The creates an XML file that looks like:
<?xml version="1.0" encoding="UTF-8"?>
<SampleXML>
<ChildNode a="yes">TextValue</ChildNode>
</SampleXML>
Dwight Kelly
Apago, Inc.
dkelly@apago.com