- 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-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-10-2023 04:37 AM
Thanks @AnveshKumar M - it is working now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 09:39 AM
Hi @Saib1
You can write onchange client on variable
1.create variable with choices for roles
2 In Client Script first clear all options using clearoptions method
3.if check enrivoronment then required roles as choices using add option method