Scriptlet: Call server scriptlet in page-level script

Ion server scriptlets are custom JavaScript solutions that bring advanced functionality to your experiences. Scriptlets can be used to retrieve values from a look-up table, make calculations and perform other script-based logic.

You can call a server scriptlet in page-level JavaScript by using the liveBallScriptlet function. Here’s an example of what this line of code would look like in your page-level script:

var result = liveballScriptlet(1, "json", 'data1=' + val1 + '&data2=' + val2);

There are three parameters in this function:

  1. “1” represents the scriptlet id. To obtain the scriptlet id, navigate into the scriptlet editor in ion and view the URL in your browser window. The sscID parameter value is what you’ll use as the first parameter in the liveBallScriptlet function.
  2. The second parameter defines the scriptlet response content type. For example, you'd specify "json" as the content type if that is format the scriptlet will return.
  3. The third parameter is optional and can be leveraged to save data to the respondent prior to invoking the scriptlet. 

Let's say you have a server scriptlet that calculates the sum of x and y that you seek to invoke from page-level script. For example:

return respondent.x + respondent.y;

If this scriptlet's id is 10, below is an example that passes x and y into the scriptlet to return the sum:

var x = 1;

var y = 2;

var sum = liveballScriptlet(10, "text/plain", 'x=' + x + '&y=' + y);


To read more about server scriptlets, please check out the post "Scriptlet: Server scriptlets for global sets of page rules & advanced functionality".