- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 05:53 AM
Hi All,
I need to add the few values in select box by using the Client Script. Please help me
Based on the Environment , i need to add the Roles on the below select box
For example :
if select
Environment - Test
Role - Admin, ITIL, cmdb_read
if select
Environment - Beta
Role - ITIL, cmdb_read
like wise i need to add 100 roles on the client script based on the environment.
How to do via the onchange client script?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 06:38 AM
Hello @Saib1
Are you getting this after updating the ScriptInclude? If yes, Please share your code.
And can you also try changing the Client Script to the below one?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("CustomRoleOptionsUtils");
ga.addParam("sysparm_name", "getRoles");
ga.addParam("sysparm_env", newValue);
ga.getXMLAnswer(populateRoles);
function populateRoles(answer){
var roles = answer.split(",");
g_form.clearOptions("roles");
var len = roles.length;
for(var i=0; i < len; i++){
g_form.addOption("roles", roles[i], roles[i]);
}
}
}
Please share your code (not screenshots, paste script as text) and screenshots of your environment variable choices again.
And please confirm, are you testing this in classic view or service portal?
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 08:23 AM
Thanks @AnveshKumar M
what this client script is doing ,i do not understand
var ga = new GlideAjax("CustomRoleOptionsUtils"); ga.addParam("sysparm_name", "getRoles"); ga.addParam("sysparm_env", newValue); ga.getXMLAnswer(populateRoles); function populateRoles(answer){ var roles = answer.split(","); g_form.clearOptions("roles"); for(key in roles){ g_form.addOption("roles", roles[key], roles[key]); } }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 08:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 08:37 AM
@Saib1 this script will get the roles based on selected environment.
Have you changed your variable names as per your configuration in the catalog item?
If it is not working, are you getting any error?
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 08:46 AM - edited 11-07-2023 08:52 AM
yes @AnveshKumar M please find the below , i am not getting any error, just data is not populated in select box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 09:05 AM
Please try this code and see, if you are getting any data in alert.
function populateRoles(answer){
alert(answer); //Add this line in your client script
var roles = answer.split(",");
g_form.clearOptions("roles");
for(key in roles){
g_form.addOption("roles", roles[key], roles[key]);
}
}
Anvesh