Custom scripting is non-functional

1

I’m getting really frustrated with custom scripting. I can’t get anything to work, even simple things, and there seems to be virtually nothing in the way of troubleshooting. 

For the script below, I’m just grabbing a selected item from a previous question, setting a hidden value to that item, and then mentioning it in a later question. The order is: previous question [page break] instruction page, script action, hidden value 1, hidden value 2 [page break] later question

Here’s the simple code:

//Grab two selected items from a chkbox question for follow-up and save
//in a couple of hidden value actions. A later question pulls from them.

// I’ve tried with both ID #s and question aliases. I’ve tried square brackets vs. curly braces.

%%selResps = sgapiGetValue(11);
%%selRespsArr = sgapiExplode(“,”,%%selResps);
sgapiSetValue(223,%%selRespsArr[0]);
sgapiSetValue(224,%%selRespsArr[1]);
%%output = %%selRespsArr[1];

The hidden values never get updated, so the later question that pulls them in via merge code displays only the default value.

I also am unable to display any %%output value, and if the how-to is in the documentation anywhere, it’s well-hidden.

Thanks in advance!

Community Admin answered
    0

    @research :

    My name is Bri. I am the documentation coordinator at SurveyGizmo. I’m plugging away at improving the scripting documentation so your post is very timely.

    When outputting arrays, you’ll need to use sgapiPrint_R in order to do so. You can see an example here:

    https://script.surveygizmo.com/help/sgapiprintr

    Regarding Hidden Values, they have a tendency to hang on to their original value. In scripting if you are trying to reset a Hidden Value you’ll need to pair it with sgapiSubmitSurvey in order to do so. Here’s a quick example script:

    //reset merge code

    sgapiSetValue(3,”Hello World”);
    sgapiSubmitSurvey();

    Hopefully this gets you over the hump!

    Bri Hillmer
    Documentation Coordinator
    SurveyGizmo Customer Experience Team

    Community Admin commented
      • Thanks, Bri. A couple of things:
        – I shouldn’t need sgapiPrint_R, should I? I think I was outputting a scalar value from the array rather than a slice or the whole thing — %%selRespsArr[1].
        – If I use sgapiSubmitSurvey() in my production code, will that prematurely submit the whole survey? That would be scary.
        – And off-topic, this page (https://help.surveygizmo.com/help/merge-code-intro) tells me how to grab fill-in text from an Other – Write In box, but when I use it, the code still returns the radio button wording (i.e., “Other – Write In”) rather than the filled-in text. Is the merge code broken? Here’s the line that grabs it:
        %%theMerge = “[question(‘option value’), id=’21’, option=’10166-other’]”;
        And I’ve tried it both with and without the “-other” on the end.

      • @research:
        sgapiSubmitSurvey submits the data from the current page and records the response as a partial. All data from previous pages will be stored for reporting.

        Note: this will not submit the current page and move to the next. To do that, use sgapiJumpToPage.

        You can learn more about that here: https://script.surveygizmo.com/help/sgapisubmitsurvey

        This code worked to pull other text using the merge code:
        %%theMerge = ‘[question(“option value”), id=”2″, option=”10008″]’;
        %%output = sgapiEvaluteMergeCodes(%%theMerge)

        Bri Hillmer
        Documentation Coordinator
        SurveyGizmo Customer Experience Team

      ×

      Login

      Question stats

      • Active
      • Views1276 times
      • Answers1 answer
      • Followers1 follower