- 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 11:00 AM
@Varun Sharma Update your code as follows.
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()?g_form.getActionName():'submit';
console.log(actionName) // this returns none
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 10:28 PM
Hi Sandeep,
Thanks for responding.
it's not working i think bcs the MRV action name is "Add"( as you can see in the screenshot attached) , it's possible that this action might be defined on Widget.
so , this isn't working as expected.
Regards,
Varun Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 10:41 PM
This the error i'm getting on Console, if using my own script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 11:00 AM
Are you getting the field message? What happens if you move getActionName up to the main function before the GA? Are you getting the expected response/ errorString?