
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 09:03 AM
Hi,
I have a catalog item that users should only be able to submit if they are a manager of the user. I want to enable a pop-up if the opened by is not the requested for's manager to tell them they can't, and cancel submission.
Can anyone help me with how to go about this?
Many thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 11:05 AM
Hi @Community Alums , please update the script as below.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var requestedFor=g_form.getValue('requested_for');
var loggedInUser = g_user.userID;
var user = g_form.getReference('requested_for',doAlert);
function doAlert(user)
{
var manager =user.manager;
if(loggedInUser != manager)
{
g_form.addErrorMessage('You are not user manager so can not submit the request');
}
}
}
Thanks,
Pooja M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 09:08 AM - edited 02-16-2023 09:19 AM
Hi,
They way you suggested is more reactive, person will fill the whole form and when they hit submit you tell them they cant, that is not a very good User Experience.
I would suggest you do it this way.
When someone opens the form, they only see the people for who the logged in person is the manager
You can add a reference qualified in the Requested For field to only show the users who have logged in User as their manager. If you want you can add a note also that the field will show your team only.
Here is a simple Variable and reference qualifier to help you achieve the same.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 06:39 AM
thanks, I get what you mean, but the requirement is to allow them to see the users and select, rather than restricting and then they don't know why they don't see the users and don't know why. It's the first field on the form so won't affect User experience too much, hopefully!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 09:13 AM - edited 02-16-2023 09:14 AM
Hello,
You can configure OnSubmit Catalog Client Script for this.
function onSubmit() {
var requestedFor = g_form.getValue('variables.requested_for');//Please check the name of variable
var requestedForManager = new EfficientGlideRecord('sys_user');
requestedForManager.addQuery('user_name', requestedFor);
requestedForManager.query();
if (requestedForManager.next()) {
var manager = requestedForManager.getValue('manager');
var openedBy = g_form.getValue('opened_by');
if (openedBy != manager) {
alert('You can only submit this request if you are the manager of ' + requestedFor);
return false; // cancel submission
}
}
return true; // allow submission
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 03:52 AM
Thanks Prasad, unfortunately this doesn't work, the EfficientGlideRecord throws an error.