- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Trying to design a catalog form where if the it checks the logged in user - and if that user’s “Is Manager” property = true, then one of the attachment variable that required for manager approval is hidden.
From what I’ve found online this needs to be done as client script instead of catalog UI policy - is that correct? I’m having trouble scripting this one and would be grateful for any ideas. Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Dee123 ,
you can create a catalog client script please follow below steps -
- Name: Hide Manager Attachment
- Catalog Item: Select your item
- UI Type: All or Desktop
- Type: onLoad
function onLoad() {
// Get the logged-in user's sys_id
var userSysId = g_user.userID;
// Call a GlideAjax script to check if the user is a manager
var ga = new GlideAjax('CheckIfManager');
ga.addParam('sysparm_name', 'isUserManager');
ga.addParam('sysparm_user_id', userSysId);
ga.getXMLAnswer(function(response) {
var isManager = response;
if (isManager == 'true') {
// Hide the attachment variable (replace 'attachment_variable_name' with actual name)
g_form.setDisplay('attachment_variable_name', false);
}
});
}
Please mark it as complete if this resolved your query and close the thread .
Thanks,
Rithika.ch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
it's an easy requirement with onLoad catalog client script + GlideAjax
what did you start with and where are you stuck?
GlideAjax Example Cheat Sheet (UPDATED)
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
3 weeks ago
Hi @Dee123 ,
you can create a catalog client script please follow below steps -
- Name: Hide Manager Attachment
- Catalog Item: Select your item
- UI Type: All or Desktop
- Type: onLoad
function onLoad() {
// Get the logged-in user's sys_id
var userSysId = g_user.userID;
// Call a GlideAjax script to check if the user is a manager
var ga = new GlideAjax('CheckIfManager');
ga.addParam('sysparm_name', 'isUserManager');
ga.addParam('sysparm_user_id', userSysId);
ga.getXMLAnswer(function(response) {
var isManager = response;
if (isManager == 'true') {
// Hide the attachment variable (replace 'attachment_variable_name' with actual name)
g_form.setDisplay('attachment_variable_name', false);
}
});
}
Please mark it as complete if this resolved your query and close the thread .
Thanks,
Rithika.ch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thanks @ChallaR ,
I created the catalog client script and made sure to change put in the actual variable name - but now when I load the form, I get the error: "There is a JavaScript error in your browser console"
I deleted the catalog client script I just made, and the error was gone -- unsure why it did not work for me. Do I need to create something else - like a server-side script or this should work with just the client-side script you provided? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thanks Rithika,
I created the catalog client script using the above and made sure to replace the variable name -- but I now get an error when loading the catalog form: "There is a JavaScript error in your browser console"
I then tried deactivating that client script -- error was gone. Unsure why it didn't work for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago