Reference Guide

Detailed explanations of every feature and function in Nutshell

Script

The Script component allows you to effectively ‘hack’ Nutshell by running custom JavaScript within an app. If you really need to do something clever that Nutshell’s pre-built components can’t do on their own, the script component is your friend.

Sreenshot

Script component on Canvas

However, to do anything with the Script component, you need to be able to write JavaScript. Basic JavaScript is beyond the scope of this reference guide, so if you’ve never written a line of code before, this probably isn’t the best place to start.

If you are a JavaScript developer, we’ll leave the possibilities to you, and explain how you get data into and out of the Script component.

How it works

The Script component takes any number of inputs – references to form fields elsewhere in the workflow, or to variables you’ve set up in your Data tab – which can be processed using custom JavaScript – for example, to perform complex calculations or to build custom strings.

The Script component then allows you to define a single output value, which can be passed along to the next step in the workflow. The final output is defined using the following method:

MicroAppScript.setResult(YOUR VALUE);

This can then be passed to a subsequent step in the workflow, or saved to a variable for future use.

Daisy-chaining Scripts

Script components can be daisy-chained one after another along your workflow, should you need to create more than one output.

Sreenshot

Multiple Scripts linked together on the Canvas

When linked like this, each Script can access the output of the last using the following method:

MicroAppScript.getResult();

Writing Code

Within the properties panel on the right, click ‘edit script content’ to write your code. You’ll see a comment already in there, explaining how you can define your output.

Sreenshot

The Script editor

You’ll also notice some basic styling tools to help you make your code a little easier to understand, and the lightning button to insert data dynamically – either from a form field elsewhere in your workflow, or from a variable.

Inputs

You can reference any form field in the workflow from within your Script. Simply place your cursor where you’d like the data to be inserted and click the lightning button.

Sreenshot

Input sources using the lightning button

It’ll ask you whether you want to insert data from a form field, or from a variable. Once you’ve chosen your data source, a placeholder will be inserted.

Sreenshot

Input source identified by source type

Be sure to choose a field from a screen that comes before the Script in the workflow, otherwise it mightn’t have a value when the Script is run!

Output

Usually, a Script will have an output of some sort. For example, if the Script is performing a complex calculation, the resulting number will be the output. If the Script is building an XML node tree, then the result will be an XML string.

Whatever the output, you must define it somewhere before the end of the Script, and it will be available to the next step in the workflow. To pass it on, you must link out of the Script to the next step, and select the outgoing link.

Sreenshot

Outgoing link with properties panel selections

In the Properties panel for the link, you’ll notice an extra block for Script Options. If you open this block up, you’ll see three options available to you:

None
Selected by default, this simply ignores any output and continues along the link regardless.

Save to Form Field
This lets you choose a form field on the next Screen into which you can insert the output. If you select this option, when the end-user arrives at the next Screen, the chosen field will be pre-populated with the output from your Script.

Save to Variable
This lets you choose a variable from your Data tab (if you have any defined), into which you can insert the output. If you select this option, any subsequent step in your workflow can reference this output – for example, using it to select a record from your Nutshell database.

If you chose to save the output to a form field on the subsequent Screen, you’ll notice an icon appear on the link to indicate this.

Script Properties

When a Script component is selected on the Canvas, the following settings are available in the Properties panel:

Basic Settings
Label An optional name, that appears on the Canvas. This makes reading larger workflows much easier.

Just getting started? Try the Tutorials section for handy quick-start guides.

Prefer to watch the action? Try our series of short video tutorials.

Can't find what you're looking for?

If you can't find the answer to your problem here, please contact Nutshell's support team via our dedicated help desk.