- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 08:40 AM
Hi,
Can anyone send me the script to validate that two field values are not the same in service catalog.
Regards
Suman P.
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 08:54 AM
Hi,
Use something like this :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return; }
//Type appropriate comment here, and begin script below
var first_user = g_form.getValue('first reference field name'); //Update the field name here
if(first_user == newValue)
{ alert('User can not be the same');
g_form.clearValue('second reference field'); //Update the field name here
} }
Learn more on Operators for comparing from here: https://docs.servicenow.com/en-US/bundle/sandiego-platform-user-interface/page/administer/navigation...
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 08:48 AM
Hi ServiceNow User,
if(g_form.getValue("variable1") != g_form.getValue("variable2")){
//fields are different, do something
}
else{
//fields are equal, do something
}
Please mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Filipe Cruz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 08:54 AM
Hi,
Use something like this :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return; }
//Type appropriate comment here, and begin script below
var first_user = g_form.getValue('first reference field name'); //Update the field name here
if(first_user == newValue)
{ alert('User can not be the same');
g_form.clearValue('second reference field'); //Update the field name here
} }
Learn more on Operators for comparing from here: https://docs.servicenow.com/en-US/bundle/sandiego-platform-user-interface/page/administer/navigation...
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 09:35 AM
Hi there,
What's the reason for asking about a script? Have you considered a UI Policy?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field