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:32 AM
Can you please which type of catalog client script are you using.
After function there onChange/onLoad details of client script missing.
Please wrap the code line in the predefined ServiceNow catalog client script function.
Mark correct if resolve the query.
--
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 05:28 AM
I tried adding it as Catalog Client Script in related links in the selected catalog item. And script was On Submit
 
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 04:48 AM
your script doesn't look like a client script
The syntax is wrong
Your logic is correct though.
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