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

Tai Vu
Kilo Patron
Kilo Patron

Hi @Sanchita02 

From your script you will figure out this error message under the browser console.

GlideAjax.getXMLWait is no longer supported

 

More important, the GlideAjax (Asynchronous) does not work on onSubmit Client Script. This is because of the fundamental behavior of Asynchronous scripts which are non-blocking by nature. So the form will get submitted before the response returning.

Let's try this approach below.

Timi_0-1729676303043.png

 

Ref: Onsubmit catalog client script is not aborting the form from submitting.

KB. KB0783579

 

Cheers,

Tai Vu