Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Unhandled exception in GlideAjax

jatin24j242424
Tera Contributor
function onChange(control, oldValue, newValue, isLoading) {
    if (newValue == '') {
        g_form.setMandatory("first_name", false);
        g_form.setDisplay("first_name", false);
        g_form.setMandatory("Last_name", false);
        g_form.setDisplay("Last_name", false);
       return;
    }

    //Type appropriate comment here, and begin script below
 
  g_form.setMandatory("first_name", false);
        g_form.setDisplay("first_name", false);
        g_form.setMandatory("Last_name", false);
        g_form.setDisplay("Last_name", false);
   var gAjax = new GlideAjax("global.DevDecisionTableUtils");
    gAjax.addParam("sysparm_name", "getVariableName");
    gAjax.addParam("sysparm_company_code", newValue);
    gAjax.getXML(function(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var answerSplit = answer.split(",");
        for (var i = 0; i < answerSplit.length; i++) {
            g_form.setDisplay(answerSplit[i], true);
        }
    });

}



 
===================================================
Script Include 
 
var DevDecisionTableUtils = Class.create();
DevDecisionTableUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getVariableName: function() {
        var company_code = this.getParameter("sysparm_company_code");
        gs.info("Variable List : " + company_code);
        var resultName = [];
        var questionName = [];
        try {
            var inputs = {};
            var companyRec = new GlideRecord("core_company");
            companyRec.get(company_code);
            inputs['u_company_code'] = companyRec; // Reference, Sys ID of the record

            var dt = new sn_dt.DecisionTableAPI();
            var response = dt.getDecisions('a5a3131d4544570985g7660a08ba19rb', inputs);

            for (var i = 0; i < (response && response.length); i++) {
                var result = response[i];
                var result_elements = result.result_elements;
                resultName.push(result_elements.u_variable_list.getValue()); // Reference

            }

            gs.info("Variable List1 : " + resultName);

            var grRec = new GlideRecord("item_option_new");
            grRec.addEncodedQuery("sys_idIN" + resultName.toString());
            grRec.query();
            while (grRec.next()) {
                questionName.push(grRec.name.toString());
            }
            gs.info("Variable List2 : " + questionName);


        } catch (e) {
            gs.info("Couldn't run this script Error: " + e)
        }

        return questionName.toString();
    },

    type: 'DevDecisionTableUtils'
});
4 REPLIES 4

vermaamit16
Kilo Patron

Hi @jatin24j242424 

 

Are you getting the info messages you have logged? Can you please share the exact error with some relevant screenshots ?

 

Thanks and Regards

Amit Verma

Thanks and Regards
Amit Verma

Hi Amit, 

 

Thats correct, I am getting this error 'Unhandled exception in GlideAjax' after logging into Service Portal.

@jatin24j242424 

 

I can see you have kept some logging statements in your Script Include. Are you able to see those info logs ? You need to go to System Logs and check them to see where your Script Include is failing to execute.

Thanks and Regards
Amit Verma

olimanalo
Mega Guru

Hi @jatin24j242424,

 

You can try the step-by-step process from DScroggins. Try returning all values as an object and call it as a JSon in your client script. 

https://www.servicenow.com/community/developer-forum/unhandled-exception-in-glideajax/m-p/1424600

 

Regards,

Oli