- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 10:08 PM
Currently this alert is pop on selection of every field in the form, before submitting the form. I want it to pop up on only 1 field when the form is submitted.
any solution to my query?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 10:22 PM
This script will generate an alert if no Locations is submitted, since you only check if they are equal.
Maybe you should add a check so see if they contain a value first, before evaluating if they are the same?
function onSubmit() {
var primaryLocation = g_form.getValue('u_primary_location');
var secondaryLocation = g_form.getValue('u_secondary_location');
if (primaryLocation || secondaryLocation) { // added check so see if any location contains a value
if (primaryLocation == secondaryLocation) {
alert('Primary Location and Secondary Location cannot be same');
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 10:29 PM
Hi @Mehar Naaz,
Open the particular form and configure the client script (onChange or onSubmit) for that and check the condition.
Regards,
Himanshu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 10:13 PM
Hi,
What are the conditions for this script to launch ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 10:15 PM
it should be on submit of the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 10:19 PM
did you identify from where this is coming? that will help you understand the script and update the logic
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 10:29 PM
Hi @Mehar Naaz,
Open the particular form and configure the client script (onChange or onSubmit) for that and check the condition.
Regards,
Himanshu