How to create a Dataset using a script?

Post Reply
reprokaiser
Newbie
Posts: 16
Joined: Mon Apr 04, 2011 3:56 pm

How to create a Dataset using a script?

Post 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
Evan
Member
Posts: 30
Joined: Mon Feb 28, 2011 6:44 pm

How to create a Dataset using a script?

Post 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);

}




rzacherl
Member
Posts: 36
Joined: Mon Mar 21, 2011 3:29 pm

How to create a Dataset using a script?

Post 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
reprokaiser
Newbie
Posts: 16
Joined: Mon Apr 04, 2011 3:56 pm

How to create a Dataset using a script?

Post 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
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

How to create a Dataset using a script?

Post 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
Post Reply