- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2014 08:14 AM
I'm trying to compare two reference variables on a catalog item and if the second one matches the first one, alert the user of the duplication and clear the contents of the second variable. First reference variable is new_site_owner and the second reference variable is new_site_owner2 Below is the catalog client script I am using woth Type: OnChange and Variable Name: new_site_owner2. Is this the correct way to compare two reference variables? Thanks
function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading || newValue == '') {
return;
}
if(newValue == g_form.getValue('new_site_owner')) {
alert("Owners cannot be the same");
g_form.setValue('new_site_owner', '');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2014 01:14 AM
Hi Chris,
Use the () after the toString since it is a function. I hope this would solve your issue.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('new_site_owner2').toString() == g_form.getValue('new_site_owner').toString()) {
alert("The primary site owner and the secondary site owner cannot be the same person");
g_form.setValue('new_site_owner2', '');
}
}
You can also use the below condition if you writing onchange script on new_site_owner2 field.
if (newValue == g_form.getValue('new_site_owner').toString()) {
Regards
Viswanath

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2014 03:18 AM
Can you try with the below script
function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading || newValue == '') {
return;
}
if(g_form.getDisplayBox('new_site_owner2').value== g_form.getDisplayBox('new_site_owner').value) {
alert("Owners cannot be the same");
g_form.setValue('new_site_owner', '');
}
}
Please let me know if you have any questions.
Thanks,
Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2014 05:21 PM
Pradeep,
Thanks for your reply. I tried the script you provided, but it did not work. If I set the reference variables new_site_owner and new_site_owner2 to the same value, nothing happens.
I've tried the below script, but this throws up the alert for any vaules I put in the two variables.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue('new_site_owner2').toString == g_form.getValue('new_site_owner').toString) {
alert("The primary site owner and the secondary site owner cannot be the same person");
g_form.setValue('new_site_owner2', '');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2014 10:43 PM
It is working fine on the below demo
https://demo007.service-now.com/login.do
Username:admin,Password:admin
Steps for testing:Navigate to Service catalog->Maintain items->Access
Thanks,
Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2014 05:13 AM
Viswanath,
Adding the () to the end of the toString resolved my problem. Thank you for your assistance.