Page 1 of 1

How to output calculated value to txt

Posted: Mon May 12, 2014 11:08 am
by RBJ
Hello



I have this javascript that I want to output the calculated value to a txt file.



I just do not what to do, I've tried several times with "XSLT transforms", but without any success.



Are there any who can help me?







var theDataset = job.getDataset( "Xml" );

var Stans = theDataset.evalToString( "/Order/Stans" );

var Quantity = theDataset.evalToString( "/Order/Quantity" );



var stansValue = 0;



var ekstraAntal = 0;



var antalSider = 0;

var result = 0;

{

switch (Stans) {







case "001D":

stansValue =2;

break;



case "002D":

stansValue =2;

break;





default:



stansValue;



}









switch (stansValue) {



case 1:



ekstraAntal = 10;



break;



case 2:



ekstraAntal = 6;



break;



default:



ekstraAntal = 4;



}





if (Quantity

How to output calculated value to txt

Posted: Mon May 12, 2014 12:01 pm
by freddyp
This looks like it is a script expression. You could output a text file from a script expression, but Switch would not be aware of it and you could not use it in the flow to route it to where it has to go.



You have to create a script using SwitchScripter and in there you write the text file and you send it on to the outgoing connection.



function jobArrived( s : Switch, job : Job )

{

var textFile = new File(s.createPathWithName(job.getNameProper()+".txt"));

textFile.open(File.WriteOnly);

textFile.writeLine("this is a line");

textFile.close();

job.sendToSingle(textFile);

}



Make sure to set the number of outgoing connections of the script to 1.



Freddy

How to output calculated value to txt

Posted: Thu May 15, 2014 9:55 pm
by Terkelsen
Hi Freddy,



I have an almost similar need, where I want to output a text-file with information stored in the JobState.



Could a similar script be used to do that and if so, how do I call the information from JobState with the script?

How to output calculated value to txt

Posted: Thu May 15, 2014 11:23 pm
by dkelly
textFile.writeLine( job.getVariableAsString("[Job.JobState]") );

How to output calculated value to txt

Posted: Fri May 16, 2014 2:07 pm
by Terkelsen
Hi Freddy and Dwight,



Based on your previous posts I have created the following script in SwitchScripter:



function jobArrived( s : Switch, job : Job )

{

var textFile = new File(s.createPathWithName(job.getNameProper()+".txt"));

textFile.open(File.WriteOnly);

textFile.writeLine( job.getVariableAsString("[Job.JobState]") );

textFile.close();

job.sendToSingle(textFile);

}



I have set the following properties:

Incoming connections: Yes

Require at least one: Yes

Outgoing connections: One

Require at least one: Yes

Connection type: Move

Execution mode: Serialized



I have saved this script package and loaded it into a Script Element in Switch in a flow with just an incoming and an outgoing folder.



If I place a file in the incoming folder, nothing happens. Where do I go wrong??

How to output calculated value to txt

Posted: Fri May 16, 2014 2:43 pm
by dkelly
Change last line to job.sendToSingle(textFile.fullName);



sendToSingle() takes a filename not a File class.

How to output calculated value to txt

Posted: Fri May 16, 2014 8:14 pm
by Terkelsen
Perfect, Dwight! That was it. Thank you.