Catalog client script issue to replace getxmlwait

priceless
Tera Expert

Hi Team

I have an Catalog Client Script (OnSubmit) where in recommendation is to replace getxmlwait function. Referred below 2 article but still am getting various java errors while submitting catalog.

Error; error there is a javascript error in your browser console servicenow

 

Appreciate if any suggestion on this please.

 

https://www.servicenow.com/community/developer-articles/getxmlwait-alternative-for-service-portal/ta...

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579

 

script:

 

function onSubmit() {
    if (g_scratchpad.isFormValid)
return true;
    var cat_id = gel('sysparm_item_guid').value;
    var gr = new GlideRecord("sys_attachment");
    gr.addQuery("table_name", "sys_data_source");
    gr.addQuery("table_sys_id", cat_id);
    gr.query();
    if (!gr.next()) {
        g_form.addErrorMessage("You must attach a Excel file to submit.");
        return false;
    } else {
        // check the lines of the uploaded Excel
        // check the script include
var ga = new GlideAjax('check_Excel_Row_count');
        ga.addParam('sysparm_name', 'getRowCount');
        ga.addParam('sysparm_xlssysid', gr.sys_id);
// ga.getXMLWait();
//ga.getXMLAnswer(getAnswer);
        answer = ga.getAnswer(); //getAnswer() retrieves the result for you
        if (answer) {
            var returneddata = JSON.parse(answer);
            g_form.setValue("qty", returneddata.counter);
            g_form.setValue("guidcheck", returneddata.guidCheck);
            g_form.setValue("hasGUID", returneddata.hasGUID);
            g_form.setValue("hasIMEI", returneddata.hasIMEI);
            g_form.setValue("imeicheck", returneddata.imeiCheck);
            var model_category = g_form.getValue("model_category");
            var hasGUID = g_form.getValue("hasGUID");
            var hasIMEI = g_form.getValue("hasIMEI");
        
            if ((model_category != "1233" && hasIMEI == "true")) {
                g_form.addErrorMessage("xyz");
                return false;
            }
            //Personal computer
            if ((model_category != "157575a" && hasGUID == "true")) {
                g_form.addErrorMessage("xyz");
                return false;
            }
            //Personal computer
            if ((model_category == "94ca" && hasGUID != "true")) {
                g_form.addErrorMessage("xyz");
                return false;
            }
            popupWait();
        }
}
function popupWait() {
    var gdw = new GlideDialogWindow('showLoadingDialogUI');
    gdw.setTitle('Please wait until the ' + g_form.getValue("qty") + ' lines in the excel are validated');
    gdw.removeCloseDecoration();
return false;
}
var actionName = g_form.getActionName();
        g_scratchpad.isFormValid = true;
        g_form.submit(actionName);
}
6 REPLIES 6

Thanks Abhijeet for response, So no need to call further call to set true for following?

var actionName = g_form.getActionName();
g_scratchpad.isFormValid = true;
g_form.submit(actionName);

Hello @priceless that will depend on your requirement If the form should be submitted automatically after the validation and data retrieval steps, then the g_form.submit(actionName) would be necessary.

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 

Thanks and Regards,
Abhijeet Pawar.