getXmlWait not working even with the alternative method on Multirow variable set

Varun Sharma
Tera Expert

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

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @Varun Sharma 

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

View solution in original post

7 REPLIES 7

Sandeep Rajput
Tera Patron
Tera Patron

@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.

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

 

 

VarunSharma_0-1700720734456.png

 

This the error i'm getting on Console, if using my own script 

 

VarunSharma_3-1700721688169.png

 

Brad Bowman
Kilo Patron
Kilo Patron

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?