Page 1 of 1

Script Expression and set action list

Posted: Thu Jan 18, 2024 8:49 am
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.

Re: Script Expression and set action list

Posted: Thu Jan 18, 2024 9:21 am
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.

Re: Script Expression and set action list

Posted: Thu Jan 18, 2024 9:26 am
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.

Re: Script Expression and set action list

Posted: Mon Mar 04, 2024 8:20 am
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;
}

Re: Script Expression and set action list

Posted: Mon Mar 04, 2024 8:25 am
by JimmyHartington
Thanks r.zegwaard

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