- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2025 05:52 AM
Hello,
I have a catalog UI policy applied to a catalog item. It is making a variable on the catalog form read-only on load.
Requirement is to make this variable editable for users whose falls under certain departments. (user.department.id == 400123,400234,400345 and so on)
How can I include this condition in the UI policy?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2025 06:12 AM
not possible using UI policy
Please use onLoad catalog client script + GlideAjax and check if logged in user department ID IS ONE OF those values
Script Include: It should be client callable
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function() {
var id = this.getParameter('sysparm_userID');
var allowedDepartments = ['400123', '400234', '400345']; // Add your department IDs here
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id); // Use valid field name here
gr.query();
if (gr.next()) {
if (allowedDepartments.indexOf(gr.department.id.toString()) != -1) {
return 'found';
} else {
return 'not found';
}
}
return 'not found';
},
type: 'checkRecords'
});
onLoad client script:
function onLoad() {
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_user.userID);
ga.getXMLAnswer(function(answer) {
if (answer == 'found')
g_form.setReadonly('variableName', false);
else
g_form.setReadonly('variableName', true);
});
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-05-2025 05:55 AM
Hi @dvelloriy
In UI policy add a condition
user.department.id is one of them and mentions the required ID.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2025 06:09 AM
Tried that already. Its applied on catalog item. Conditions wont show me dot walked fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2025 06:13 AM
Correct, then you need to use the Client scripts where you need mention these deatils.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2025 06:12 AM
not possible using UI policy
Please use onLoad catalog client script + GlideAjax and check if logged in user department ID IS ONE OF those values
Script Include: It should be client callable
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function() {
var id = this.getParameter('sysparm_userID');
var allowedDepartments = ['400123', '400234', '400345']; // Add your department IDs here
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id); // Use valid field name here
gr.query();
if (gr.next()) {
if (allowedDepartments.indexOf(gr.department.id.toString()) != -1) {
return 'found';
} else {
return 'not found';
}
}
return 'not found';
},
type: 'checkRecords'
});
onLoad client script:
function onLoad() {
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_user.userID);
ga.getXMLAnswer(function(answer) {
if (answer == 'found')
g_form.setReadonly('variableName', false);
else
g_form.setReadonly('variableName', true);
});
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader