Hello,
Is there a way to write multi-lines text using variables to a file?
I want to write an XML using PDF metadata and XML data from my MIS.
The only way I found is to send an email, retreive it and inject message as file.
I'm looking now to create a custom configurator but it is a little hard without nothing to start with. All .sscript file I found are lock with a password.
Where I can find an unlock .sscript file? Is somebody can create me a configurator that will doing it? It should not be hard to do but I'm new to javascript.
Enfocus should add this tool in the next update. It is a basic thing to do giving a lot of possibilities.
Thanks!
Write to file configurator using multi-lines with variable
-
dkelly
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
You can access variables via Switch's Javascript getVariableAsString() call.
Give me the name of variables you want to write and I'll generate you an example. Do you want each variable on a separate line, comma-separated, etc?
Give me the name of variables you want to write and I'll generate you an example. Do you want each variable on a separate line, comma-separated, etc?
Hi dkelly,
I want to be able to put free text around variable and create lines.
Here two variable
[Metadata.Text:Path="/powerswitch/preflight",Dataset="Xml",Model=XML]
[Stats.NumberOfPages]
The result should be a text file containing:
cmykcoated
32
Thanks for your time.
I want to be able to put free text around variable and create lines.
Here two variable
[Metadata.Text:Path="/powerswitch/preflight",Dataset="Xml",Model=XML]
[Stats.NumberOfPages]
The result should be a text file containing:
cmykcoated
32
Thanks for your time.
-
dkelly
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
This snippet should work; however, I haven't had time to test it in a real flow so there maybe a syntax issue or two with quoting.
var myFile = new File("/Users/dkelly/Desktop/out.xml");
myFile.open( File.WriteOnly | File.Truncate );
myFile.writeLine("<powerswitch>");
myFile.writeLine(" <preflight>" + job.getVariableAsString("[Metadata.Text:Path="/powerswitch/preflight",Dataset="Xml",Model=XML]", s) + "</preflight>");
myFile.writeLine(" <numberofpages>" + job.getVariableAsString("[Stats.NumberOfPages]", s) + "</numberofpages>");
myFile.writeLine("</powerswitch>");
myFile.close();
var myFile = new File("/Users/dkelly/Desktop/out.xml");
myFile.open( File.WriteOnly | File.Truncate );
myFile.writeLine("<powerswitch>");
myFile.writeLine(" <preflight>" + job.getVariableAsString("[Metadata.Text:Path="/powerswitch/preflight",Dataset="Xml",Model=XML]", s) + "</preflight>");
myFile.writeLine(" <numberofpages>" + job.getVariableAsString("[Stats.NumberOfPages]", s) + "</numberofpages>");
myFile.writeLine("</powerswitch>");
myFile.close();
Thanks dkelly it works but I don't want to write a new script every time. I found a better way like i was asking at first.
Now I can write everything I want using the multi-lines with variable dialog box and using all variable available into Powerswitch. I can also choose the file extension.
The script is:
function jobArrived( s : Switch, job : Job )
{
var extension = s.getPropertyValue("Extension");
var tempFile = job.createPathWithExtension(extension);
var myFile = new File(tempFile);
var TextToWrite = s.getPropertyValue("Text_to_Write");
var InputJob = job.getPath();
myFile.open( File.WriteOnly | File.Truncate );
myFile.writeLine(TextToWrite);
myFile.close();
job.sendToSingle(InputJob);
job.sendToSingle(tempFile)
}
For newbies like me:
For make it work a "Text_to_Write" and "Extension" Flow Element Properties in SwitchScripter must be create.
Then into Powerswitch choose into tool "Script Element" and choose the .sscript file you save from SwitchScripter.
This is my first configurator. No guaranty on it! It surely have more efficient way to doing it. But I think Enfocus should include something like this in the installation package.
Now I can write everything I want using the multi-lines with variable dialog box and using all variable available into Powerswitch. I can also choose the file extension.
The script is:
function jobArrived( s : Switch, job : Job )
{
var extension = s.getPropertyValue("Extension");
var tempFile = job.createPathWithExtension(extension);
var myFile = new File(tempFile);
var TextToWrite = s.getPropertyValue("Text_to_Write");
var InputJob = job.getPath();
myFile.open( File.WriteOnly | File.Truncate );
myFile.writeLine(TextToWrite);
myFile.close();
job.sendToSingle(InputJob);
job.sendToSingle(tempFile)
}
For newbies like me:
For make it work a "Text_to_Write" and "Extension" Flow Element Properties in SwitchScripter must be create.
Then into Powerswitch choose into tool "Script Element" and choose the .sscript file you save from SwitchScripter.
This is my first configurator. No guaranty on it! It surely have more efficient way to doing it. But I think Enfocus should include something like this in the installation package.
- JimmyHartington
- Member
- Posts: 28
- Joined: Tue Mar 22, 2011 7:38 am
Hi
I have used this script to write a text-file.
It seems that the text-file is encoded as ISO-8859.
But I would like to get a UTF-8 encoded file.
Does anybody know how to do this?
I have used this script to write a text-file.
It seems that the text-file is encoded as ISO-8859.
But I would like to get a UTF-8 encoded file.
Does anybody know how to do this?
Hi Jimmy,
Try
function jobArrived( s : Switch, job : Job )
{
var extension = s.getPropertyValue("Extension");
var tempFile = job.createPathWithExtension(extension);
var myFile = new File(tempFile, "UTF8");
var TextToWrite = s.getPropertyValue("Text_to_Write");
var InputJob = job.getPath();
myFile.open( File.WriteOnly | File.Truncate );
myFile.writeLine(TextToWrite);
myFile.close();
job.sendToSingle(InputJob);
job.sendToSingle(tempFile)
}
The line I change is:
var myFile = new File(tempFile, "UTF8");
--
Evan
Try
function jobArrived( s : Switch, job : Job )
{
var extension = s.getPropertyValue("Extension");
var tempFile = job.createPathWithExtension(extension);
var myFile = new File(tempFile, "UTF8");
var TextToWrite = s.getPropertyValue("Text_to_Write");
var InputJob = job.getPath();
myFile.open( File.WriteOnly | File.Truncate );
myFile.writeLine(TextToWrite);
myFile.close();
job.sendToSingle(InputJob);
job.sendToSingle(tempFile)
}
The line I change is:
var myFile = new File(tempFile, "UTF8");
--
Evan
- JimmyHartington
- Member
- Posts: 28
- Joined: Tue Mar 22, 2011 7:38 am
Hi Evan
Thanks. That worked perfect.
Now I have another question.
Could this script be modified to instead of writing a new file, then it would add a line to the begining of an incoming text-file?
For example to insert a header row to incoming tab-delimited text-files, which does not have the header row.
Thanks. That worked perfect.
Now I have another question.
Could this script be modified to instead of writing a new file, then it would add a line to the begining of an incoming text-file?
For example to insert a header row to incoming tab-delimited text-files, which does not have the header row.
Hi Jimmy,
This maybe not the more efficient way to do it but it works.
function jobArrived( s : Switch, job : Job ){
var extension = s.getPropertyValue("Extension");
var tempFile = job.createPathWithExtension(extension);
var myFile = new File(tempFile, "UTF8");
var InputPath = job.getPath();
var myHeader = s.getPropertyValue("Text_to_Write");
var inputFileText = File.read(InputPath);
myFile.open( File.WriteOnly | File.Truncate );
myFile.writeLine(myHeader);
myFile.writeLine(inputFileText);
myFile.close();
job.sendToSingle(tempFile);
job.sendToNull(InputPath);
}
--
Evan
This maybe not the more efficient way to do it but it works.
function jobArrived( s : Switch, job : Job ){
var extension = s.getPropertyValue("Extension");
var tempFile = job.createPathWithExtension(extension);
var myFile = new File(tempFile, "UTF8");
var InputPath = job.getPath();
var myHeader = s.getPropertyValue("Text_to_Write");
var inputFileText = File.read(InputPath);
myFile.open( File.WriteOnly | File.Truncate );
myFile.writeLine(myHeader);
myFile.writeLine(inputFileText);
myFile.close();
job.sendToSingle(tempFile);
job.sendToNull(InputPath);
}
--
Evan
- JimmyHartington
- Member
- Posts: 28
- Joined: Tue Mar 22, 2011 7:38 am
Hi Evan
Fantastic. This just works.
And if I need to add a line at the bottom, I imagine I would make a new variable linking to a new property and add it after myFile.writeLine(inputFileText);
Fantastic. This just works.
And if I need to add a line at the bottom, I imagine I would make a new variable linking to a new property and add it after myFile.writeLine(inputFileText);
Exactly, to make your code more robust you should add a try-catch routine so if an error occur your job will go to the problem folder and an error log will be generated.
function jobArrived( s : Switch, job : Job )
{
try {
var extension = s.getPropertyValue("Extension");
var tempFile = job.createPathWithExtension(extension);
var myFile = new File(tempFile, "UTF8");
var InputPath = job.getPath();
var myHeader = s.getPropertyValue("Text_to_Write");
var inputFileText = File.read(InputPath);
myFile.open( File.WriteOnly | File.Truncate );
myFile.writeLine(myHeader);
myFile.writeLine(inputFileText);
myFile.close();
job.sendToSingle(tempFile);
job.sendToNull(InputPath);
}
catch(e)
{
job.fail(e)
}
}
--
Evan
function jobArrived( s : Switch, job : Job )
{
try {
var extension = s.getPropertyValue("Extension");
var tempFile = job.createPathWithExtension(extension);
var myFile = new File(tempFile, "UTF8");
var InputPath = job.getPath();
var myHeader = s.getPropertyValue("Text_to_Write");
var inputFileText = File.read(InputPath);
myFile.open( File.WriteOnly | File.Truncate );
myFile.writeLine(myHeader);
myFile.writeLine(inputFileText);
myFile.close();
job.sendToSingle(tempFile);
job.sendToNull(InputPath);
}
catch(e)
{
job.fail(e)
}
}
--
Evan
-
Peter Kleinheider
- Newbie
- Posts: 17
- Joined: Mon Dec 13, 2010 4:52 pm
For creating XML files, I use a script from impressed called "XML magic".
a multiline filed with variables let you specify the structure of the resulting xml and looks like
& Element /customer jobs
& Element /customer/jobs job
+ Attribute /customer/jobs/job name [Job.NameProper]
+ Attribute /customer/jobs/job group [Job.Hierarchy:Index=1]
+ Attribute /customer/jobs/job outputtype [Job.Hierarchy:Index=2]
+ Element /customer/jobs/job options
+ Element /customer/jobs/job/options option
+ Attribute /customer/jobs/job/options/option[[last()] name printpdf
+ Text /customer/jobs/job/options/option[[last()] 1
The resulting XML looks like:
1
The script allows to modify the content of the job itself (if the job is a XML file) or modify the XML as dataset.
You can create new XML files or modify existing XML files.
This is the number 1 script I use when creating flows based on metadata.
a multiline filed with variables let you specify the structure of the resulting xml and looks like
& Element /customer jobs
& Element /customer/jobs job
+ Attribute /customer/jobs/job name [Job.NameProper]
+ Attribute /customer/jobs/job group [Job.Hierarchy:Index=1]
+ Attribute /customer/jobs/job outputtype [Job.Hierarchy:Index=2]
+ Element /customer/jobs/job options
+ Element /customer/jobs/job/options option
+ Attribute /customer/jobs/job/options/option[[last()] name printpdf
+ Text /customer/jobs/job/options/option[[last()] 1
The resulting XML looks like:
1
The script allows to modify the content of the job itself (if the job is a XML file) or modify the XML as dataset.
You can create new XML files or modify existing XML files.
This is the number 1 script I use when creating flows based on metadata.