- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 05:31 AM
Hi All,
How we can add dynamic dropdown choices to a variable without any custom table. I have one orchestration activity and getting output response as below.
{ "databasename":"",
"datasource":"testdatasource",
"instancename":"dev123",
"output":"\n\nname\n----\nA\nABC_Test\nABC_test0\nABC_test0_TDE\nABC_test1\nABC_test2\nABC_test3\nABC_test3_new\nABC_test5\nABC_test6\nABC_test7\nABC_test8\nABC_TEST9\ntest0520\ntest1001\ntest1002\ntest1003\ntest1004\ntest1006\ntest1007\ntest500\ntest501\ntest502\ntest503\ntest504\ntest505\ntest506\ntest507\ntest508\n",
"serverInstance":"testSERVER,143",
"sqlPort":"143398",
"sqlquery":"SELECT name FROM master.sys.databases WHERE name NOT IN('master','msdb','model','tempdb','AdminDB')"
}
I need to take "output" from this json then split with \n. The remaining answers/responses after splitting with \n i should add as a drop down choices.
Is it possible?
Regards,
Sirraj
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 09:51 PM
where are you storing the response ? are you using script include to fetch he response of json ?
are you able to get the json response in client script ? if yes then use the same logic part which i had mentioned , so instead glide record , you will directly use addOption() to set the choices in your client script.
you have to write here onChange catalog client script on your database name variable and you will get json response and parse it and then set it using addOption()
eg:
var json= {
"databasename":"",
"datasource":"testdatasource",
"instancename":"dev123",
"output":"\n\nname\n----\nA\nABC_Test\nABC_test0\nABC_test0_TDE\nABC_test1\nABC_test2\nABC_test3\nABC_test3_new\nABC_test5\nABC_test6\nABC_test7\nABC_test8\nABC_TEST9\ntest0520\ntest1001\ntest1002\ntest1003\ntest1004\ntest1006\ntest1007\ntest500\ntest501\ntest502\ntest503\ntest504\ntest505\ntest506\ntest507\ntest508\n",
"serverInstance":"testSERVER,143",
"sqlPort":"143398",
"sqlquery":"SELECT name FROM master.sys.databases WHERE name NOT IN('master','msdb','model','tempdb','AdminDB')"
}
var ab = JSON.stringify(json);
var obj = JSON.parse(ab);
var arr = obj.output.split('\n');
for(var k in arr){
if(arr[k] != ''){
g_form.addOption('Variable NAme' ,arr[k],arr[k]);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 06:38 AM
But i have catalog variable. we need to go with addoption, removeoption rite? For adding choices to the variable field.
please correct me if i am wrong.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 06:42 AM
for variable choices store in question_choice table so change the table and check the mandatory attributes required and use that in script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 06:47 AM
for testing i had created below code.
var json= {
"databasename":"",
"datasource":"testdatasource",
"instancename":"dev123",
"output":"\n\nname\n----\nA\nABC_Test\nABC_test0\nABC_test0_TDE\nABC_test1\nABC_test2\nABC_test3\nABC_test3_new\nABC_test5\nABC_test6\nABC_test7\nABC_test8\nABC_TEST9\ntest0520\ntest1001\ntest1002\ntest1003\ntest1004\ntest1006\ntest1007\ntest500\ntest501\ntest502\ntest503\ntest504\ntest505\ntest506\ntest507\ntest508\n",
"serverInstance":"testSERVER,143",
"sqlPort":"143398",
"sqlquery":"SELECT name FROM master.sys.databases WHERE name NOT IN('master','msdb','model','tempdb','AdminDB')"
}
var ab = JSON.stringify(json);
var obj = JSON.parse(ab);
//gs.print(obj.output.split('\n'));
var arr = obj.output.split('\n');
for(var k in arr){
if(arr[k] != ''){
var gr = new GlideRecord('question_choice');
gr.initialize();
gr.question='b8b5af312f5ddc10f68d5ff62799b6b4'; // my variable sys_id
gr.text=arr[k];
gr.value=arr[k];
gr.insert();
}
}
result

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 08:39 AM
its up to you, you can either directly create the choices on your variable , because choices store in question_choice table. it will be server side .
if you are going with client script then you can use addOption().

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 06:07 AM
you can try something like below.
var json= {
"databasename":"",
"datasource":"testdatasource",
"instancename":"dev123",
"output":"\n\nname\n----\nA\nABC_Test\nABC_test0\nABC_test0_TDE\nABC_test1\nABC_test2\nABC_test3\nABC_test3_new\nABC_test5\nABC_test6\nABC_test7\nABC_test8\nABC_TEST9\ntest0520\ntest1001\ntest1002\ntest1003\ntest1004\ntest1006\ntest1007\ntest500\ntest501\ntest502\ntest503\ntest504\ntest505\ntest506\ntest507\ntest508\n",
"serverInstance":"testSERVER,143",
"sqlPort":"143398",
"sqlquery":"SELECT name FROM master.sys.databases WHERE name NOT IN('master','msdb','model','tempdb','AdminDB')"
}
var ab = JSON.stringify(json);
var obj = JSON.parse(ab);
var arr = obj.output.split('\n');
for(var k in arr){
var gr = new GlideRecord('incident');
gr.initialize();
gr.short_description=arr[k];
gr.insert();
}
Note: for testing i considered incident table to create that much of record which i am getting a choices. so you just change the table as sys_choice and set the attribute which is required to create a choice in sys_choice table.
If my answer helped you, kindly mark it as correct and helpful.