SELECT BOX

NannuSubhani Sh
Tera Contributor

HI 

in Rest message GET response we are  getting the names list i need to display those names list in variable &the variable type is select box (names_list)  ..those names are dynamic if new value coming in rest message response i need to create new question choice in select box variable (names_list) automatically by script can anyone help me out in the script for at least with one name which are showing in below rest message response..so that i can move forward

 

NannuSubhaniSh_0-1669808454227.png

 

 

5 REPLIES 5

Hi Goutham,

 

By using the below script question choices are created but now the problem is when ever we are loading the catalog item (for example there 50 names in the rest message response these 50 names are continuously creating when ever we are loading the form )  

we need to add condition to the below script kindly suggest

 

var timezone = Class.create();
timezone.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 

getCategories: function() {

try {
var r = new sn_ws.RESTMessageV2('restmessage Access', 'get zonenames');

//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);

//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');

//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);

var response = r.execute();

var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log('status' + httpStatus, 'sh31');

var arr = responseBody.split(',');
// gs.log('response body ' + arr[i], 'sh30');
//var order =100;
for(i=0;i<=arr.length;i++){
var choices = new GlideRecord('question_choice');
choices.initialize();
choices.question='848e17541b6211503a95ed30604bcb0d';
choices.text=arr[i];
choices.value=arr[i];
gs.log('response body ' + arr[i], 'sh30');
choices.insert();
}
} catch (ex) {
var message = ex.message;
gs.log('exeption ' + message, 'sh30');
}

},
type: 'timezone'
});