Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

OnSubmit() Client script cannot working on Workspace

Sanchita02
Tera Contributor

I have a issue with my client script. It is working as expected in native UI but not in workspace.

 

UI Type is "ALL" & Isolate script is checked to "True"

 

 

Client Script

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var currentAttribute = (g_form.getValue('u_type_of_attribute'));
    var currentApplication = (g_form.getValue('u_application'));
    var curremtMF = (g_form.getValue('u_member_firm'));
    var currentTitle = (g_form.getValue('u_title'));

    var checAttributes = new GlideAjax("x_kpm94_ce.GQRM_Client_Evaluation_ClientUtils");
    checAttributes.addParam('sysparm_name', 'checkduplicateAttribute');
    checAttributes.addParam('sysparm_attribute', currentAttribute);
    checAttributes.addParam('sysparm_application', currentApplication);
    checAttributes.addParam('sysparm_memberfirm', curremtMF);
    checAttributes.addParam('sysparm_title', currentTitle);
    checAttributes.getXMLWait();

    var answer = checAttributes.getAnswer();
    if (answer == 'true') {
        return false;
    } else {
        return true;
    }
}
 
 
1 ACCEPTED SOLUTION

hi @Sanchita02 ,

 

can you try below code

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var currentAttribute = (g_form.getValue('u_type_of_attribute'));
    var currentApplication = (g_form.getValue('u_application'));
    var curremtMF = (g_form.getValue('u_member_firm'));
    var currentTitle = (g_form.getValue('u_title'));

    var checAttributes = new GlideAjax("x_kpm94_ce.GQRM_Client_Evaluation_ClientUtils");
    checAttributes.addParam('sysparm_name', 'checkduplicateAttribute');
    checAttributes.addParam('sysparm_attribute', currentAttribute);
    checAttributes.addParam('sysparm_application', currentApplication);
    checAttributes.addParam('sysparm_memberfirm', curremtMF);
    checAttributes.addParam('sysparm_title', currentTitle);
    checAttributes.getXML(function(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");

        if (answer == 'true') {
            return false;
} else {
            g_form.setValue('submit_flag', true); // Indicate that the form can be submitted
            // Optionally submit the form or allow the default behavior
        }  });
}

 

Please mark helpful & correct answer if it's really worthy for you.

 

Thanks,

BK

View solution in original post

5 REPLIES 5

Bhavya11
Kilo Patron
Kilo Patron

hi @Sanchita02 ,

 

Unfortunately it won't work in workspace.Please note that the use of getXMLWait() is no longer supported.

 

Please mark helpful & correct answer if it's really worthy for you.

 

Thanks,

BK

 

 

 

@Bhavya11  Is there any other option for getXMLWait()

hi @Sanchita02 ,

 

can you try below code

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var currentAttribute = (g_form.getValue('u_type_of_attribute'));
    var currentApplication = (g_form.getValue('u_application'));
    var curremtMF = (g_form.getValue('u_member_firm'));
    var currentTitle = (g_form.getValue('u_title'));

    var checAttributes = new GlideAjax("x_kpm94_ce.GQRM_Client_Evaluation_ClientUtils");
    checAttributes.addParam('sysparm_name', 'checkduplicateAttribute');
    checAttributes.addParam('sysparm_attribute', currentAttribute);
    checAttributes.addParam('sysparm_application', currentApplication);
    checAttributes.addParam('sysparm_memberfirm', curremtMF);
    checAttributes.addParam('sysparm_title', currentTitle);
    checAttributes.getXML(function(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");

        if (answer == 'true') {
            return false;
} else {
            g_form.setValue('submit_flag', true); // Indicate that the form can be submitted
            // Optionally submit the form or allow the default behavior
        }  });
}

 

Please mark helpful & correct answer if it's really worthy for you.

 

Thanks,

BK

hi @Bhavya11  - conditions are meeting property, but  it is not preventing the page to save from

 

Following part is not working:

 if (answer == 'true') {
                return false;