How to output calculated value to txt

Post Reply
RBJ
Newbie
Posts: 2
Joined: Mon Jul 11, 2011 1:19 pm

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
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

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
User avatar
Terkelsen
Member
Posts: 126
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

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

textFile.writeLine( job.getVariableAsString("[Job.JobState]") );
User avatar
Terkelsen
Member
Posts: 126
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

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

Change last line to job.sendToSingle(textFile.fullName);



sendToSingle() takes a filename not a File class.
User avatar
Terkelsen
Member
Posts: 126
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Perfect, Dwight! That was it. Thank you.
Post Reply