'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 try modifying your code to below code if this helps

OmkarKumbhar2_0-1672920028895.png

Also, Please check this below link

https://www.servicenow.com/community/developer-forum/syntaxerror-unexpected-end-of-json-input/m-p/18...

 

Thanks,

Omkar

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

Hi @Omkar Kumbhar  I did try the following code:

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

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

ubsrec.push(row.ubs_mrvs_reinstate).toString();

    }

 

Unfortunately that made no difference.

jaheerhattiwale
Mega Sage

@matthew_hughes There must be some error in "checkProvderRecipientSubgroupsJurisdiction" function of "LBGSPCAjaxUtilsscript include. As its used in GlideAjax. Please check that.

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

This is the code for the 'checkProviderRecipientSubgroupsJurisdiction' within the script include:

 

checkProviderRecipientSubgroupsJurisdiction: function() {

 

        var result = this.newItem("result");

        var mrvs = this.getParameter('mrvs');

        // gs.log('JT: ' + mrvs);

        //var mrvs current.variables.ubs_table_update; //Table of UBS records to update (multi-row variable set)

        var providerCount = 0;

        var jurisdictionCountProvider= 0;

        var recipientCount = 0;

        var jurisdictionCountRecipient = 0;

 

        var capProv = new GlideRecord('u_cmdb_ci_capability_provisioning');

        capProv.addQuery('sys_id', 'IN', mrvs);

      //capProv.setLimit(1);

        capProv.query();

 

        while (capProv.next()) {

            //Check if provider is rfb

            if (capProv.u_provider.u_subgroup == 'rfb') {

                providerCount++;

          }

 

          //check if jurisdiction is Germany or netherlands for the provider

            if (capProv.u_provider.u_jurisdiction.includes(gs.getProperty('LBG.recipient.jurisdiction.germany')) || capProv.u_provider.u_jurisdiction.includes(gs.getProperty('LBG.recipient.jurisdiction.germany2')) || capProv.u_provider.u_jurisdiction.includes(gs.getProperty('LBG.recipient.jurisdiction.Netherlands'))) {

                jurisdictionCountProvider++;

            }

 

            //check if recipient rfb 

            if (capProv.u_recipient.u_subgroup != 'rfb') {

              recipientCount++;

           }

 

            //check if jurisction is Germany or netherlands

            if (capProv.u_recipient.u_jurisdiction.includes(gs.getProperty('LBG.recipient.jurisdiction.germany')) || capProv.u_recipient.u_jurisdiction.includes(gs.getProperty('LBG.recipient.jurisdiction.germany2')) || capProv.u_recipient.u_jurisdiction.includes(gs.getProperty('LBG.recipient.jurisdiction.Netherlands'))) {

               jurisdictionCountRecipient++;

            }

 

        }

    if (providerCount >= 1 && recipientCount >= 1) {

            result= 'true';

        } else if (providerCount >= 1 && jurisdictionCountProvider >= 1 && jurisdictionCountRecipient >= 1 && recipientCount == 0) {

           result = 'true';

        } else {

            result = 'false';

        }

        // gs.log('JT providerCount: ' + providerCount);

       // gs.log('JT recipientCount: ' + recipientCount);

        // gs.log('JT jurisdictionCount: ' + jurisdictionCount);

        return result;

    },