Error Msg: There is a JavaScript error in your browser console - Service Portal - Washington

CandiceS
Tera Contributor

I must be overlooking something in this script. I originally had this Catalog Client Script with UI type = All.

I now have created two CCS, one for Desktop and another one for Mobile/Service Portal. I am assuming the Mobile/Service Portal will require adjustments, just not knowing what it is I am missing.  

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    g_form.addInfoMessage("Please wait while the system validates the Policy Number. Estimated time 20 seconds....");
    var polNum = g_form.getValue('policy_number');
    //alert(polNum);

    var ga = new GlideAjax('u_PolicyServiceAJAX'); //script include
    ga.addParam('sysparm_name', 'getPolicyByNumber');
    ga.addParam('sysparm_policy_number', polNum);
    ga.getXML(validatePolicy);

}

function validatePolicy(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    //alert(answer);

    var returneddata = answer.evalJSON(true);
    var dataResult = returneddata.result;
    // alert(returneddata.result);

    if (dataResult == 'success') {
        g_form.addInfoMessage('Policy Number is valid, please continue with request.');
    } else {
        g_form.addErrorMessage('Policy Number is not valid, please validate your information');
        g_form.clearValue('policy_number', true);
   

    }

}
2 ACCEPTED SOLUTIONS

Maik Skoddow
Tera Patron
Tera Patron

Without more details about the printed error it is only guessing 😞
The only thing I find suspicious is

var returneddata = answer.evalJSON(true);

Replace it with

var returneddata = JSON.parse(answer);

 

View solution in original post

Community Alums
Not applicable

@CandiceS ,

eval.JSON is not supported in Portal. Instead use JSON.parse().

Refer these for more info: Link1 & Link2

 

If my answer helped you in any way, please mark it as helpful or correct.

View solution in original post

3 REPLIES 3

Maik Skoddow
Tera Patron
Tera Patron

Without more details about the printed error it is only guessing 😞
The only thing I find suspicious is

var returneddata = answer.evalJSON(true);

Replace it with

var returneddata = JSON.parse(answer);

 

Thank you so much, I will remember this going forward.

Community Alums
Not applicable

@CandiceS ,

eval.JSON is not supported in Portal. Instead use JSON.parse().

Refer these for more info: Link1 & Link2

 

If my answer helped you in any way, please mark it as helpful or correct.