Restrict some variables to users from a specific Division
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-30-2022 09:41 PM
Hi
Very new here with very limited coding experience.
We have a form that is used by the entire company.
A request has come in to add two new variables (a checkbox and custom notification) to the form.
They have specified that only users from 2 divisions should be able to see these new variables.
I have created the variables but I can't see how to restrict variables by divsion - fd_data.trigger.request_item.requested_for.u_business_unit
I understand we want the Requested For (user) to be a part of one of the two divisions, but I don't know how to execute this via the Catalog UI Policy.
I did some research online and found this:
if (g_user.hasRole("itil") && !g_user.hasRole("itil_admin") {
g_form.setReadOnly("<your variable name>", true);
}
else {
g_form.setReadOnly("<your variable name>", false);
}
I'm wondering if i should base it on this - but I'm not a java script whiz.
Can anyone advise of how I would script it and where that script would go?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-30-2022 11:01 PM
Hi @Brookie
So you want to restrict the variable to only specific domain users?
If yes you can achieve this by using onload catalog client script.
Perform glideAjax and get the requested for division value into client script based on it you can restrict the variable.
As said you are new to servicenow I would recommend you to follow the below article to solve your query.
Post here if any queries, happy to help:)
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-01-2022 05:17 PM
So I tried this in the Catalog UI script but it fails to work.
Any thoughts on why?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (request_item.request.requested_for.u_business_unit == "XXX" && request_item.request.requested_for.u_business_unit == "YYY") {
g_form.setDisplay("ring_fencing_checkbox", true);
}
else {
g_form.setDisplay("ring_fencing_checkbox", false);
}
//Type appropriate comment here, and begin script below
}