- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 09:03 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 09:42 PM
you can have a hidden text variable and store the flag
1) set the flag as valid in both the onchange catalog client scripts if it's valid number
2) set it as invalid if any 1 number is not valid
3) then use onSubmit and check what's the flag value and if it's valid then allow submitting
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 09:10 PM
Please check below links should help you
Please mark correct/helpful if this helps you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 09:44 PM
I have updated your code little bit, can you try once
function onSubmit() {
var phoneNumber = g_form.getValue('phone_number');
var mobileNumber = g_form.getValue('mobile_number');
// Function to validate phone numbers asynchronously
function validatePhoneNumber(number, callback) {
if (!number) {
callback(false);
return;
}
var ga = new GlideAjax('VSHUserPhoneTerritory'); // Script Include
ga.addParam('sysparm_name', 'validatePhoneNumber'); // Method
ga.addParam('fullPh', number);
ga.getXMLAnswer(function(response) {
var res = JSON.parse(response);
callback(res.valid);
});
}
return false; // Prevent form submission initially
validatePhoneNumber(phoneNumber, function(phoneValid) {
validatePhoneNumber(mobileNumber, function(mobileValid) {
if (!phoneValid && !mobileValid) {
g_form.addErrorMessage('Please enter at least one valid phone number.');
} else {
if (!phoneValid) {
g_form.clearValue('phone_number');
}
if (!mobileValid) {
g_form.clearValue('mobile_number');
}
g_form.submit();
}
});
});
return false; // Prevent immediate submission
}
Please mark correct/helpful if this helps you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 09:26 PM
don't use GlideAjax in onSubmit as synchronous calls are not supported in portal.
Why not use onChange and validate it and throw error when number is invalid?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 09:31 PM
hi ankur,
I already have it in onchange, what i want is that
if the value for both phone_number && mobile_number is invalid = avoid submitting the request.
if one of the value has a valid value = submit the request and clear the value that has invalid.
Which I am trying to do.