'SyntaxError: Unexpected end of JSON input' error message when running ATF

matthew_hughes
Kilo Sage

When I run an ATF, an error message of 'There is a JavaScript error' in your browser console' for a catalogue item on the service portal within the client test runner. However, when I view the same catalogue item on my browser, I don't get that error message.

 

When I look at the results of the ATF, it mentions the following message:

 'Error while running Client Script "Check subGroups and Juridiction - Reinst": SyntaxError: Unexpected end of JSON input'

 

When I open the "Check subGroups and Juridiction - Reinst" catalog client script, I can't see any syntax issues. The client script can be found below:

 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == '') {

        return;

    }

 g_form.clearValue('provider_subgroup_is_rfb');

    var mrvsUbsRec = '';

    var conditionsMet = 'false';

    var mrvs = JSON.parse(g_form.getValue('ubs_table_reinstate'));

   //Iterate each row in the UBS table (multi row variable set)

    var ubsrec = [];

 

    for (var i = 0; i < mrvs.length; i++) {

       var row = mrvs[i]; //individual row

        ubsrec.push(row.ubs_mrvs_reinstate);

    }

    mrvsUbsRec = ubsrec.toString();

 //alert('The value of mrvs s ' + mrvs);

 //alert('The value of mrvs is ' + mrvs.toString());

 //art('The value of mrvsUbsRec is ' + mrvsUbsRec.toString());

    //alert(mrvsUbsRec: '+mrvsUbsRec);

 

    var checkConditions = new GlideAjax("LBGSPCAjaxUtils");

    checkConditions.addParam("sysparm_name", "checkProvderRecipientSubgroupsJurisdiction");

    checkConditions.addParam("mrvs", mrvsUbsRec);

    checkConditions.getXML(processResponse);

 //alert('e value of checkConditions is ' + checkConditions);

 

    function processResponse(response) {

        var result = response.responseXML.documentElement.getAttribute("answer");

        conditionsMet = result;

      //alert("departsubGroup value is " + departsubGroup);

  //alert('The value of mrvs is ' + mrvs);

  //alert('The value of mrvs is ' + mrvs.toSting());

  //alert('The value of result is '  result);  //alert('The value of conditionsMet is ' + conditionsMet);

 

        if (conditionsMet== 'true') {

            g_form.setVaue('provider_subgroup_is_rfb', 'true');

        }

    }

}

 

If somebody could let me know if there's anything wrong with the code, that would be great.

8 REPLIES 8

Omkar Kumbhar
Mega Sage

Hello @matthew_hughes ,

Can you please split this and try once

var mrvs = JSON.parse(g_form.getValue('ubs_table_reinstate'));

Write the below code:

var MRVSvalue= g_form.getValue('ubs_table_reinstate') ;   //Please check the variable name is correct 

var mrvs= JSON.parse(MRVSvalue);

I tried that. Unfortunately it didn't work. 'ubs_table_reinstate' is a variable within a variable set of the catalogue item. 

jaheerhattiwale
Mega Sage

@matthew_hughes 

You must add VARIABLE SET INTERNAL NAME in getValue function.

 

var mrvs= JSON.parse(g_form.getValue('<VARIABLE SET INTERNAL NAME HERE>') );

 

jaheerhattiwale_0-1672928302293.png

 

 

Please check and add variable set internal name and try.

 

Please mark as correct answer if this solves your issue.

Hi @jaheerhattiwale In this scenario, for var mrvs = JSON.parse(g_form.getValue('ubs_table_reinstate'));, 'ubs_table_reinstate' is the internal name.

 

Unfortunately, it's made no difference.