- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2016 03:47 PM
ServiceNow Scripting Experts,
I need help with my simple client script. It it OnChange and field is Knowledge Base.
What I want to happen is when the select their knowledge base, I want to assign their roles to it so only their department can see their knowledge base.
When I create a new article and put in Retail Tech in the Knowledge Base field - it does work as expected and assign the roles to 'retail technology'. BUT
if I put in Operations & Support - the roles goes to "retail technology" and not "operations_support". What am I doing wrong!?
Yes, I am new to scripting so please forgive me if I am missing something simple.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var gr = new GlideRecord("kb_knowledge_base");
if (gr.kb_knowledge_base = "Retail Tech"){
g_form.setValue("roles", "retail technology");
}
else if (gr.kb_knowledge_base = "Operations & Support"){
g_form.setValue("roles", "operations_support");
}
}
Thanks in advance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2016 10:47 AM
Hi Adam,
Without doing a call to the server to find the name for your sys_id in-hand, I think you could use the following client-side:
var checkValue = g_form.getDisplayBox('kb_knowledge_base').value;
if (checkValue == "Operations & Support"){
g_form.setValue("roles", "operations_support");
}
This is for example only, please make sure to fill in with your correct values for comparisons, etc.
See how that works.
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2016 11:13 AM
Nevermind - I believe it is working correctly.