VMware Aria Automation Orchestrator

 View Only
  • 1.  VRO NodeJS Scriptable task return

    Posted Jul 27, 2022 06:16 PM

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

     



  • 2.  RE: VRO NodeJS Scriptable task return

    Posted Jul 28, 2022 05:48 AM

    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

     

     



  • 3.  RE: VRO NodeJS Scriptable task return

    Posted Jul 28, 2022 05:50 AM

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

     



  • 4.  RE: VRO NodeJS Scriptable task return

    Posted Jul 28, 2022 05:52 AM

    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.



  • 5.  RE: VRO NodeJS Scriptable task return

    Posted Jul 28, 2022 03:18 PM

    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 ?



  • 6.  RE: VRO NodeJS Scriptable task return

    Posted Dec 15, 2022 07:05 AM

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