Script Expression and set action list

Post Reply
User avatar
JimmyHartington
Advanced member
Posts: 310
Joined: Tue Mar 22, 2011 7:38 am

Script Expression and set action list

Post by JimmyHartington »

I am trying to convert some legacy script expressions to node.JS script exprissions.

Old code

Code: Select all

var colorRotate = job.getVariableAsString( "[Stats.Colorants]" );
var basePath = "\\\\FILE01-MB\\Fælles\\Grafiske Brugere\\Pitstop Action Lists\\Kunderelaterede\\0-9\\2care4_75152900\\Packagingflow\\";

switch (true) {
	case (colorRotate.indexOf('EMANAT-0') >= 0):
		actionlist = 'EMANAT-01 - Set art box and place HTML-0°.eal';
		break;
	case (colorRotate.indexOf('EMANAT-90') >= 0):
		actionlist = 'EMANAT-01 - Set art box and place HTML-90°.eal';
		break;
}
var actionlistPath = basePath + actionlist;

actionlistPath
I am a bit unsure how to get the Stats.Colorants info.
It seems I can get Private Data, but this is not private data.

And it also could be I will solve this with a Pitstop Profile, where I use a variable set to toggle the action lists on and off.

But it would be a good exercise to convert it to node.JS for me.
freddyp
Advanced member
Posts: 1023
Joined: Thu Feb 09, 2012 3:53 pm

Re: Script Expression and set action list

Post by freddyp »

Unfortunately we do not (yet) have the job.getVariableAsString function in NodeJS scripting. The recommended workaround for this is to place whatever it is you need in your script expression in private data and then use that private data in your script expression. It is not perfect, but it is not difficult either.
User avatar
JimmyHartington
Advanced member
Posts: 310
Joined: Tue Mar 22, 2011 7:38 am

Re: Script Expression and set action list

Post by JimmyHartington »

Thanks Freddy.

I thought that also could be a work around.
Some of my other expressions uses private data, so I know that works.
r.zegwaard
Member
Posts: 93
Joined: Fri Jul 08, 2011 10:31 am
Location: The Netherlands

Re: Script Expression and set action list

Post by r.zegwaard »

Hi Jimmy,

I agree that job.getVariableAsString etc should be available in the node.js script-expressions. It would make migrating from legacy to node.js script-expressions much easier.

But...

The Enfocus Scripting docs provide a function getXpath() that can easily be used to get data from datasets, also in Script-Expressions
Just copy/paste the function to your script-expression.
See: https://www.enfocus.com/manuals/Develop ... thods.html


Code: Select all

...
    result = await getXpath(job, dataset, "string(/root/message)");
...

// Function getXpath
async function getXpath(job: Job, dataset: string, xpath: string): Promise<string> {
    let result: string | number | boolean;
    try {
        const datasetPath = await job.getDataset(dataset, AccessLevel.ReadOnly);
        const XML = XmlDocument.open(datasetPath);
        const NSmap = XML.getDefaultNSMap();
        const evaluation = XML.evaluate(xpath, NSmap);
        result = evaluation as string;
        await job.log(LogLevel.Warning, xpath + " " + result as string);
    } catch (error: any) {
        result = error.message;
    }
    return result as string;
}
User avatar
JimmyHartington
Advanced member
Posts: 310
Joined: Tue Mar 22, 2011 7:38 am

Re: Script Expression and set action list

Post by JimmyHartington »

Thanks r.zegwaard

I will look into this, when I revisit my migration from legacy to Node.js script expressions.
Post Reply