Hi, trying my hand at some node.js actions \ scriptable tasks in VRO 8.8.
I am struggling to find away to return \ pass data from task to the next.
I have a workflow with 2 scriptable tasks, task1 has a single input call execTime and a single output called output. These are both defined as variables in the workflow and liked accordingly to the scriptable task. I have tried using return output, return variable_goes_here. But I can not get this to what I want.
Below is a simple bit of code without any return. What would I need to do to get the code to return one of the date variables.
Also what is the purpose of the callback, I see nothing about this documented anywhere I looked.
exports.handler = (context, inputs, callback) => {
console.log('Inputs were ' + JSON.stringify(inputs));
console.log('Inputs were ' + JSON.stringify(context));
console.log(typeof inputs.execTime);
var nyDate = new Date(inputs.execTime).toLocaleString('en-gb', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
timeZone: 'America/New_York'
});
var zarDate = new Date(inputs.execTime).toLocaleString('en-gb', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
timeZone: 'Africa/Johannesburg'
});
var jpnDate = new Date(inputs.execTime).toLocaleString('en-gb', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
timeZone: 'Asia/Tokyo'
});
console.log(nyDate)
console.log(zarDate);
console.log(jpnDate);
callback(undefined, {status: "done"});
}
So, even though the Date is one of the supported return types by a Node.js script in vRO,
It doesn't seem to work.
However, we can use toString() and set the return type to String. this worked for me.
In node.js, A callback is a function which is called when a task is completed, thus helps in preventing any kind of blocking and a callback function allows other code to run in the meantime. Callback is called when task get completed and is asynchronous equivalent for a function.
So based on what I see from your screenshot it looks like you are showing the view from Cloud Assembly | Extensibility | Actions.
Where as I am referring to VRO. I did try what you suggested but still no luck.
UPDATE: So I took the code I had in the scriptable task and moved it into an action. Then took that action and added it as a workflow element and then things worked.
Interestingly in the logs I now see this
Inputs were {"execTime":"2022-08-01T03:12:00.000+00:00"}
Inputs were {"executionId":"c893ca67-effd-4304-a652-7f4188bfd85e","returnType":"string","vcoUrl":"http://localhost:8280/vco"}
Note how returntype is string
where as before when the code was just in a Scriptable task
Inputs were {"execTime":"2022-07-31T20:14:00.000+00:00"}
Inputs were {"executionId":"f2bec819-9f15-434e-a7f3-82f1f68f3b94","returnType":null,"vcoUrl":"http://localhost:8280/vco"}
Note how returnType is null
Would love to understand why this is ?
Hi APJ_vm,
Have you found the answer to why a scripted task doesn't return any value while the action script does?
And probably - whether there is a way to use Node.js in scriptable tasks and have the ability to return values (or expose global variables)?