- 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 07:02 AM
Hi Ankur,
Its not working and giving this error
AbstractAjaxProcessor undefined, maybe missing global qualifier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2025 08:11 AM
ensure you create script include and client script in same scope.
Seems you are working in scoped app and trying to create script include + client script in global scope
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 08:59 AM
Hi Ankur,
I created both script include and client script in scoped app only.
Issue got fixed when i updated the below line of code and included global.AbstractAjaxProcessor instead.
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {