Node JS 14.16.1

Prev Next

Skillable Studio allows execution of scripts against a cloud subscription, as well as executing scripts that do not have a target. Scripts are used in Automated Activities and Life Cycle Actions.

This script execution environment is running Node.js 14.16.1.

Your scripts can communicate success or failure to Skillable Studio in one of two ways.

//do stuff... all good
return true;
JavaScript
//do stuff... uh oh
return false;
JavaScript
//do stuff... all good
setActivityResult(true);
JavaScript
//do stuff... uh oh
setActivityResult(false);
Plain text

You can also report the result as a score %...

//do stuff... we want to report success and set the score value as 50%
setActivityResult(0.5);
JavaScript

Notifications appear as real-time toast notification in the lab client.

sendLabNotification("A notification from Node.js!");
JavaScript

Lab variables are always string name/value pairs. Variable values are scoped to the lab instances and become available within the lab instructions as well as subsequent script executions.

setLabVariable("myVariable1", "This was set by Node.js in the cloud!");
JavaScript

You can "receive" a variable in your script...

#a variable set elsewhere in the lab, but we can use it in our script
const myVariable1 = "@lab.Variable(myVariable1)";
JavaScript

##Dealing with Async

It's very common to work with asynchronous JavaScript.

If you choose to use setActivityResult, the last time it is called within your script will determine the outcome.

setTimeout(function() {
    console.log("This message was left inside the async code.");
    setActivityResult(true);
}, 1000);
return false; //<- this will have no effect, as it will be evaluated before the async code is run.
JavaScript

You can use a promise and return the result to Skillable Studio by resolving the promise.

return await (new Promise((resolve, reject) => {
    setTimeout(function() {
        console.log("This message was left inside the async code.");
        resolve(true);
    }, 1000);
}));
JavaScript