[Solved] 1) early exit from custom script; 2) functions in custom scripts


I’m writing a custom script.

1) Under some conditions, I want to exit the script early.  I’ve tried exit and break (see examples below), but both seem to hang the progress of the survey.

What is the recommended way to prematurely exit a custom script?

———- examples I’ve tried ————

if (%%i == 1) exit;

if (%%i == 1) break;


2) Also, I sometimes find it useful to use functions in custom scripts. Is this possible. If so, can you give me a simple example?




Nathan - Survey Astronaut selected answer

    Best answer


    Hi Richard!

    1) SurveyGizmo’s Custom Scripting language does not contain a construct for prematurely exiting a script. If you wish to abort a script, the easiest solution may be to wrap your script in a function, and to `return` from the function to abort your script.

    function sgapiMyScript() {
    // do stuff

    if (%%shouldAbort === true) {

    // do more stuff


    2) Yep! Creating your own functions is definitely possible. Per our documentation, just be sure “any functions you create […] start with ‘sgapi.’” See the above snippet for an example of this.

    I hope this helps!

    Nathan - Survey Astronaut selected as best answer


      Question stats

      • Active
      • Views5491 times
      • Answers1 answer
      • Followers0 followers