Script vs define variables

Post Reply
Jgandersen
Newbie
Posts: 6
Joined: Tue Sep 13, 2011 4:13 pm

Script vs define variables

Post by Jgandersen »

I will make a replay mail, where you can view information about PDF,

so I've made some define variables​​, and it works fine :-D



Name [job.name]

Size (Here I will put the script)

Number of Pages [Stats.NumberOfPages]

Bytes [Job.Size]

Colours [Stats.Colorants:Separator=-]



but when I want it in mm instead of points,

so I found this script here, but now, I would like to put it together.

and make the define variables like a script



[function convert() {



var MBpt = job.getVariableAsNumber( "[Stats.TrimBoxHeight]" );

var MBmm = Math.round( MBpt * 0.35277 ).toString();







var MBpe = job.getVariableAsNumber( "[Stats.TrimBoxWidth]" );

var MBmi = Math.round( MBpe * 0.35277 ).toString();



return "Format: " + MBmi + " x " + MBmm + " mm"





}

convert();]
Peter Kleinheider
Newbie
Posts: 17
Joined: Mon Dec 13, 2010 4:52 pm

Script vs define variables

Post by Peter Kleinheider »

Jgandersen,



inside the function convert you do not have access to the "job" variable, since you have not defined it in your function call and pass it as parameter.



You can write the script without the function. There you have access to job.





var MBpt = job.getVariableAsNumber( "[Stats.TrimBoxHeight]" );

var MBmm = Math.round( MBpt * 0.35277 ).toString();







var MBpe = job.getVariableAsNumber( "[Stats.TrimBoxWidth]" );

var MBmi = Math.round( MBpe * 0.35277 ).toString();



"Format: " + MBmi + " x " + MBmm + " mm"
freddyp
Advanced member
Posts: 1022
Joined: Thu Feb 09, 2012 3:53 pm

Script vs define variables

Post by freddyp »

Peter is right about the job variable inside the function.



However, there is a flaw in the whole setup: inside the body text you can access variables, but not script expressions. You can also use a script expression for the body text, but then you can only return 1 string.



Put the string you want to use in the job state variable using the script as Peter wrote it. You can do this on any folder element along which your job passes. In the body text of the mail you can then use [Job.JobState] and you will get the string that you put in there with the script expression.
Jgandersen
Newbie
Posts: 6
Joined: Tue Sep 13, 2011 4:13 pm

Script vs define variables

Post by Jgandersen »

Many thanks to both of you, it works, and super with [job.JobState], its great :-D
Post Reply