Dynamic Scripts
JavaScript in dynamic steps and dynamic resources: the Inskill namespace a dynamic script uses to read and save task data, upload a photo, show a wait spinner, and move a step on.
Dynamic steps and dynamic resources are the same kind of content: HTML pages, shown in the app and the web portal, whose JavaScript reaches InSkill through the Inskill namespace. A dynamic script is that JavaScript. It can read and save task data, upload a photo, or show a wait spinner, and in a dynamic step it can also move the task on.
Dynamic scripts are separate from copilot scripts and Script agents, which run in the cloud. See Scripts.
Adding a Script
In a dynamic step, open the step's Content tab, switch to Advanced, and click Switch to Text Editor to edit the step body as HTML. Click Preview to try the step.
In a dynamic resource, select html on the Content tab.
In either, add the JavaScript in a <script> tag.
The Inskill Namespace
A dynamic script reaches the Technician and the running task through the Inskill namespace. Everything in it works the same in dynamic steps and dynamic resources, except Inskill.Session.message.
| Member | What it does |
|---|---|
Inskill.User | The signed-in user: firstname, lastname, name, and email. |
Inskill.Session.task | The running task: product_id, data, and asset with its id and sn (serial number). |
Inskill.Session.hasData(path, product_id) | Whether a variable has a value. |
Inskill.Session.getData(path, product_id) | The value of a variable, for example Inskill.Session.getData('error_code'). |
Inskill.Session.setData(path, value, product_id) | Saves a value in the task, like an observation, for example Inskill.Session.setData('error_code', 5). |
Inskill.Session.uploadImage(name, file) | Uploads an image and stores its URL in the task under name, as setData does. The result's url holds the address. |
Inskill.Session.message(command) | Acts for the step's buttons. Dynamic steps only — see Step Commands. |
Inskill.Utils | Helpers: empty, getData, setData, and pickKeys. See Reference. |
Inskill.UI.waitscreen(start) | Starts the wait spinner with true and stops it with false. |
product_id is optional in hasData, getData, and setData.
Step Commands
Inskill.Session.message works only in a dynamic step, because a dynamic resource has no step buttons. It takes one of three commands:
| Command | Effect |
|---|---|
{ 'continue': '' } | Moves to the next step, as if the Technician pressed Continue. |
{ 'finished': '' } | Ends the task, as if the Technician pressed Finished. |
{ 'end': '' } | Hides the step's standard buttons — Continue, Not Solved, and Finished. |
A step with Headless turned on shows no standard buttons, so its script must give the Technician a way to move on, such as a button that calls Inskill.Session.message({ 'continue': '' }). See Dynamic Steps.
Examples
// Print the task information to the browser console
console.log(Inskill.Session.task);
// Save data in the task, like any observation
Inskill.Session.setData('error_code', 5);
Inskill.Session.setData('sensors.pressure', 5);
// Dynamic steps only: move to the next step, as if the Continue button was pressed
Inskill.Session.message({ 'continue': '' });
// Dynamic steps only: end the task, as if the Finished button was pressed
Inskill.Session.message({ 'finished': '' });
// Dynamic steps only: hide the step's standard buttons
Inskill.Session.message({ 'end': '' });
// Show the wait spinner, then stop it after 5 seconds
Inskill.UI.waitscreen(true);
setTimeout(() => Inskill.UI.waitscreen(false), 5000);
// Upload an image and store its URL in the task data under 'photo'
// file is a File or Blob, for example from an <input type="file">
var input = document.getElementById('fileInput');
var result = await Inskill.Session.uploadImage('photo', input.files[0]);
// result.url holds the uploaded image's URLUpdated 1 day ago
