- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 09:55 AM
Hi Experts,
Kindly guide me with your expertise.
i'm trying to add a validation to mutli row variable set , validation should run before submitting the Row.
i've used the alternate provided by service now KB0783579.
But it's still not working, on g_form.getActionName() i'm getting action value as none.
here is the code
function onSubmit() {
var validationGa = new GlideAjax('testingRoom');
validationGa.addParam('sysparm_name', 'ValidateRoomFullName');
validationGa.addParam('sysparm_room_type', g_form.getValue('room_type'));
validationGa.addParam('sysparm_room_access', g_form.getValue('room_access'));
validationGa.addParam('sysparm_capacity', g_form.getValue('maximum_number_of_people'));
validationGa.addParam('sysparm_display_equipment', g_form.getValue('display_equipment'));
validationGa.addParam('sysparm_room_full_name', g_form.getValue('room_full_name'));
validationGa.getXMLAnswer(validationMessage);
return false;
function validationMessage(response) {
var errorString = response;
g_form.showFieldMsg('room_full_name', errorString, 'error');
if (errorString != null) {
spModal.open({
title: 'Room Full Name Error',
message: errorString,
buttons: [{
label: 'OK',
primary: true
}]
});
return false;
}
var actionName = g_form.getActionName();
console.log(actionName) // this returns none
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
}
Kindly help me through. #ServicePortal #ITSM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 10:56 PM
You're missing return true to allow user to submit once your validation is passed.
Let's try my adjustment below.
function onSubmit() {
/*** Pop this gem into your script! */
if (g_scratchpad.isFormValid) {
return true;
}
var actionName = g_form.getActionName();
var validationGa = new GlideAjax('testingRoom');
validationGa.addParam('sysparm_name', 'ValidateRoomFullName');
validationGa.addParam('sysparm_room_type', g_form.getValue('room_type'));
validationGa.addParam('sysparm_room_access', g_form.getValue('room_access'));
validationGa.addParam('sysparm_capacity', g_form.getValue('maximum_number_of_people'));
validationGa.addParam('sysparm_display_equipment', g_form.getValue('display_equipment'));
validationGa.addParam('sysparm_room_full_name', g_form.getValue('room_full_name'));
validationGa.getXMLAnswer(validationMessage);
return false;
function validationMessage(response) {
var errorString = response;
g_form.showFieldMsg('room_full_name', errorString, 'error');
if (errorString != null) {
spModal.open({
title: 'Room Full Name Error',
message: errorString,
buttons: [{
label: 'OK',
primary: true
}]
});
return false;
}
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 10:36 PM
Hi Brad,
Thanks for quick response.
I'm able to retrieve errorString and it works fine and checks all the validations , give back the pop up window. it's causing the issue only when i try to submit it , as it doesn't go through.
When i try to put the actionName outside of the function , i get the function name "submit", So when i press the add button , but it still doesn't submit the Row.
this is the alert i get when i put the actionName before Ajax call.
Regards,
Varun Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 10:56 PM
You're missing return true to allow user to submit once your validation is passed.
Let's try my adjustment below.
function onSubmit() {
/*** Pop this gem into your script! */
if (g_scratchpad.isFormValid) {
return true;
}
var actionName = g_form.getActionName();
var validationGa = new GlideAjax('testingRoom');
validationGa.addParam('sysparm_name', 'ValidateRoomFullName');
validationGa.addParam('sysparm_room_type', g_form.getValue('room_type'));
validationGa.addParam('sysparm_room_access', g_form.getValue('room_access'));
validationGa.addParam('sysparm_capacity', g_form.getValue('maximum_number_of_people'));
validationGa.addParam('sysparm_display_equipment', g_form.getValue('display_equipment'));
validationGa.addParam('sysparm_room_full_name', g_form.getValue('room_full_name'));
validationGa.getXMLAnswer(validationMessage);
return false;
function validationMessage(response) {
var errorString = response;
g_form.showFieldMsg('room_full_name', errorString, 'error');
if (errorString != null) {
spModal.open({
title: 'Room Full Name Error',
message: errorString,
buttons: [{
label: 'OK',
primary: true
}]
});
return false;
}
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 11:18 PM
Hi Tai Vu,
Thankyou so much.
It worked.
i was stuck on it from so many hours.
You are the best.
Thanks You.