- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 04:36 AM
Hello,
I'm trying to get a client script to work on the catalog but having no joy, anyone know where im going wrong? I want it to pick up which option the user has chosen and update the field based on that choice."
I seem to get "Error There is a JavaScript error in your browser console", I know it can work if I put a stand alone statement in like set a single value with no conditions but soon as I start adding in "if" conditions it doesnt like it.
function onSubmit() {
var cr = g_form.getReference("role_required");
var gr = g_form.getReference("current_role");
var rq = g_form.getValue('request_needed_role_access');
if (rq == add) {
g_form.setValue("service_desk_info", "Add role: " + cr.u_role_ad_group);
}else if
(rq == remove) {
g_form.setValue("service_desk_info", "Remove from AD Group: " + cr.u_role_ad_group);
}else if
(rq == amend) {
g_form.setValue("service_desk_info", "Remove from AD Group: " + gr.u_role_ad_group + "Add to AD group: " + cr.u_role_ad_group);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 05:17 AM
Hi,
don't set value in onSubmit
Why not set value based on change of those 2 variables?
OR
Just set the other variable once RITM is submitted via workflow run script
var cr = current.variables.role_required.u_role_ad_group;
var gr = current.variables.current_role.u_role_ad_group;
var rq = current.variables.request_needed_role_access;
if (rq == 'add') {
current.variables.service_desk_info = "Add role: " + cr;
}else if(rq == 'remove') {
current.variables.service_desk_info = "Remove from AD Group: " + cr;
}else if(rq == 'amend') {
current.variables.service_desk_info = "Remove from AD Group: " + gr + "Add to AD group: " + cr;
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 04:48 AM
Get reference won't work in service portal , use script includes and glideajax.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 04:50 AM
Then how does it work when I dont use if conditions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 04:53 AM
function onSubmit() { var cr = g_form.getReference("role_required");
var gr = g_form.getReference("current_role");
var rq = g_form.getValue('request_needed_role_access');
if (rq == "add") {
g_form.setValue("service_desk_info", "Add role: " + cr.u_role_ad_group);
}
else if (rq == "remove") {
g_form.setValue("service_desk_info", "Remove from AD Group: " + cr.u_role_ad_group);
}else if (rq == "amend") {
g_form.setValue("service_desk_info", "Remove from AD Group: " + gr.u_role_ad_group + "Add to AD group: " + cr.u_role_ad_group);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 04:56 AM
Thanks for your help but still no joy, how would I put this in a script includes? I dont use them very often.