VMware Cloud Community
APJ_vm
Enthusiast
Enthusiast

VRO NodeJS Scriptable task return

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"});
}

 

0 Kudos
5 Replies
imtrinity94
Enthusiast
Enthusiast

So, even though the Date is one of the supported return types by a Node.js script in vRO, 

imtrinity94_0-1658987284448.png

It doesn't seem to work.

imtrinity94_1-1658987323088.png

 

 


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
0 Kudos
imtrinity94
Enthusiast
Enthusiast

However, we can use toString() and set the return type to String. this worked for me.

imtrinity94_0-1658987411197.png

exports.handler = (context, inputs, callback) => {
    console.log('Input(s): ' + JSON.stringify(inputs));
    console.log('Context: ' + JSON.stringify(context));
    var nyDate = new Date().toLocaleString('en-gb', {
        year: 'numeric',
        month: 'long',
        day: 'numeric',
        hour: 'numeric',
        minute: 'numeric',
        timeZone: 'America/New_York'
    });
    console.log(nyDate);
    return nyDate.toString();
    callback(undefined, {status: "done"});
}

 


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
0 Kudos
imtrinity94
Enthusiast
Enthusiast

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.


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
0 Kudos
APJ_vm
Enthusiast
Enthusiast

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 ?

holden_ca
Contributor
Contributor

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)?

0 Kudos