If opened_by is the same as request for display message

New user1212
Tera Contributor

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');
}
})();
7 REPLIES 7

SupriyaWaghmode
Kilo Sage

@New user1212 -

 

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. 

 

--

Thanks & Regards ,
Supriya Waghmode |ServiceNow Consultant

 

 

I tried adding it as Catalog Client Script in related links in the selected catalog item. And script was  On Submit

New test.png

 

Ankur Bawiskar
Tera Patron
Tera Patron

@New user1212 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader