[Solved] Syntax question: Defining/evaluating a set of values; custom scripting

0

I want to automatically tag Log-In numbers with a Job Function descriptor.

This custom script works:

/*Job Function tagging – Identify 3-4 Part-Time Employees by their Log-In Number; the majority are Full-Time */

%%source_id = 33; //Textbox question id (filtered for numbers only)

%%target_id = 153; //target Textbox question id (used to tag Log-In Number with Job Function)

if(sgapiGetValue(%%source_id) == ‘1001’){

      sgapiSetValue(%%target_id, “Part-Time”);
      
   }

elseif (sgapiGetValue(%%source_id) == ‘10014’) {

      sgapiSetValue(%%target_id, “Part-Time”);
      
   }

elseif (sgapiGetValue(%%source_id) == ‘10015’) {

      sgapiSetValue(%%target_id, “Part-Time”);
      
   }

else sgapiSetValue(%%target_id, “Full-Time”);

 

I would prefer to define an array and loop through the values.  What is the correct syntax for looping through the values?:

%%source_id = 33; //Textbox question id (filtered for numbers only)

%%target_id = 153; //target Textbox question id (used to tag Log-In Number with Job Function)

%%options = array(1 => ‘1001′,’10014′,’10015’);

%%n =1;

[loop through %%n  == (1 =< 3) ]

if(sgapiGetValue(%%source_id) == %%options{%%n} ) {

      sgapiSetValue(%%target_id, “Part-Time”);

%%n = %%n + 1;
      
   }

else sgapiSetValue(%%target_id, “Full-Time”);

 

Thanks in advance

Bruce Bindeman asked

    Best answer

    0

    I solved it!

    /*Job Function tagging – Identify 3-4 Part-Time Employees by their Log-In Number; the majority are Full-Time */

    %%source_id = 33;    //Textbox Question Id (QID) (filtered for numbers only)

    %%target_id = 153;   //Target Textbox QID id (used to tag Log-In Number with Job Function)

    /*Enter the Log-In Numbers which need a specific tag into an array*/

    %%options = array(‘1001’, ‘10014’,’10015′);         

    sgapiSetValue(%%target_id, “Full-Time”);  //Initialize the Target Textbox value

    foreach (%%options as %%key => %%value)     {    //Loop through each value in the array

    {if(sgapiGetValue(%%source_id) == %%value)         //IF there is a match, write an alternate

        {sgapiSetValue(%%target_id, “Part-Time”);}}        //label or tag into the target textbox
           
        }      

    /*The tag remains as initialized unless it matches a value in the array “%%options”*/                                         

     

    Bruce Bindeman answered
      ×

      Login

      Question stats

      • Active
      • Views260 times
      • Answers1 answer
      • Followers0 followers