sgapiSetValue(%%questionID,%%value)

Important Update to Custom Scripting

The CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!


  1. New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
  2. As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
  3. In the long term, Legacy Custom Scripting Actions will be switched to read-only. The exact date on this is to be determined; we will send notifications well ahead of time.

This function populates the response value of the given question. 

For hidden value, textbox, essay, radio button, drop-down menu, slider and image choice %%value is defined as a "string."

For checkbox and Drag & Drop %%value must be specified as an array.

To set the value of a list of dropdowns, radio button table, and checkbox table %%questionID should be specified as the ID of the table's row.

Examples

Check it out in an Example Survey

The following example will set the value of a question to be "yes." The question type could be text, essay, radio button, dropdown menu, or a hidden value action. If it is a radio button or dropdown, you need to make sure that it has the corresponding reporting value.

sgapiSetValue(2,"Yes");

Next let's set the value of a checkbox question. Let's say our checkbox question has reporting values "a", "b" and "c." Here, we tell our script to check the "a" and "c" options.

%%options = array("a","c");
sgapiSetValue(2,%%options);

For Drag & Drop Ranking questions you'll need to specify an array using the option skus like so:

sgapiSetValue(2,array('10001' => 4, '10002' => 3, '10003' => 2, '10004' => 1));

Limitations

  • sgapiSetValue cannot be used to set a value of an Admin Question on the same page. If you are using sgapiSetValue to set the value of an Admin Question it must be on a page that precedes or follows the script.
  • sgapiSetValue cannot be used to set the value of an other textbox