sgapiSetQuestionProperty(%%questionID, %%property, %%value)

Important Update to Custom Scripting

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

Legacy Custom Scripting Language Deprecation Plans 

  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 sets the given property to the given value for the given question.

Possible Properties Values
exclude_number boolean
labels_right boolean
orientation VERT/HORZ
question_description_above boolean
custom_css Template CSS hook name
required boolean
force_percent boolean
force_currency boolean
min_number value
max_number value
min_answers_per_row value
minimum_response, value value
defaulttext text/reporting value
max_total value
max_total_noshow boolean
email_attachments value
xnumber value

Examples

The below script sets the required property for question ID 10.

%%questionID = 10;
%%property = 'required';
%%value='true';

sgapiSetQuestionProperty(%%questionID, %%property, %%value);

This script utliizes the sgapiRand function in combination with the sgapiSetQuestionProperty function to randomize the orientation of the target question.

Check it out in an Example Survey

%%questionID = 2;
%%property = "orientation";
%%random = sgapiRand(0,1);

if (%%random == 0) {
    %%value = "VERT";
}
else{
    %%value = "HORZ";
}

sgapiSetQuestionProperty(%%questionID,%%property,%%value);

Using the "email_attachments" property you can attach a custom-built PDF to an existing send email action. In this example we set the "email_attachments" property of the send email action (ID 3)equal to the %%attachment custom PDF that we created.

%%pdf = "Example PDF";
%%text = "Hello World!";
%%size = 14;
%%options = array('spacing' => 1.5);
%%table = array( array(1,2,3,4), array(5,6,7,8), array (9,10,11,12) );
%%columns = array('Column A','Column B','Column C','Column D');

sgapiNewPDF(%%pdf,'letter','portrait');
sgapiSetFontPDF(%%pdf,'courier');
sgapiSetColorPDF(%%pdf,0,0,0);
sgapiImagePDF(%%pdf,"https://surveygizmolibrary.s3.amazonaws.com/library/160589/surveysoftwareapi.png"); 
sgapiTextPDF(%%pdf,%%text,%%size,%%options);
sgapiTablePDF(%%pdf,%%table,%%columns,'Table Title');

%%formattedpdf = sgapiPDFOutput(%%pdf);

%%attachment['example.pdf'] = %%formattedpdf;

sgapiSetQuestionProperty(3,"email_attachments",%%attachment);