If opened_by is the same as request for display message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 04:04 AM
Hey,
I'm working on a client script for a catalog item that will check if the request being created was created by the same person for whom access is being granted - if so, a message should be displayed that this is not appropriate for this item.
Unfortunately, I have a problem with the script, because it either completely blocks the possibility of changing the person for whom the request is being created or it doesn't drop out at all. Any ideas?
(function() {
var openedBy = g_form.getValue('opened_by');
var requestedFor = g_form.getValue('requested_for');
if (openedBy == requestedFor) {
g_form.showFieldMsg('opened_by', 'End users must not request access for themselves.', 'error');
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 04:19 AM
Hi @New user1212
May i know where you've written your script?
I've created the On load client script on Requested item table and it's working as expected. PFB
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('opened_by') == g_form.getValue('requested_for')) {
g_form.showFieldMsg('opened_by', 'End users must not request access for themselves.', 'error');
}
}
Output:
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 05:24 AM - edited ‎04-29-2025 05:29 AM
but this is created for all records from the Requested item table.
I need it to work only for two catalog items and for the message to appear on the Service Portal when we click the Request option in this window.
I thought that adding this catalog client script in the relateded links of a given catalog item would work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 06:14 AM - edited ‎04-29-2025 06:25 AM
@New user1212 I don't think you can access requested_for and opened by from the catalog client script. Because those fields will be populated only after the request submission.
In your case, change the request method as submit and create one new requested for type variable in the catalog item.
Then create one on submit catalog item to validate the requested for and current logged in user.
function onSubmit() {
//Type appropriate comment here, and begin script below
var req = g_form.getValue('requested_for');
var current_user = g_user.userID;
if (req == current_user) {
g_form.addErrorMessage("Invalid user");
return false;
}
}
Hope this helps.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 06:24 AM
So you want validation to run on Order Confirmation modal?
if yes then it's not possible there to run any catalog client script.
what's your actual business requirement?
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