Receiving this error "Javascript Error in Browser Code" in the Portal for one of the catalog item

Appu2
Tera Contributor

Hi, I am receiving this error "Javascript Error in Browser Code" in the Portal for one of the catalog item for those who don't have any roles. I am the admin or anyother with itil role does not see this error but the ones without any roles get stuck with this error on the browser.

I have created an onload Client Script for the catalog item.

Below is the code:-

function onLoad() {
 
    var ga = new GlideAjax('KPMG_nTAAPDetails');
    ga.addParam('sysparm_name', 'retrieveDetails');
    ga.getXMLAnswer(setProjectDetails);
 
    function setProjectDetails(response) {
 
        var result = JSON.parse(response);
      //  console.log(result);
        var getaccessType = result.initialValuesArray;
for (var accessTypes = 0; accessTypes < getaccessType.length; accessTypes++) {
            g_form.addOption('access_type', getaccessType[accessTypes], getaccessType[accessTypes]);
        }
var values = result.uniqueValuesMap;
 
var valueProjName = values["Business User"].u_project_name;
for (var valueIndex = 0; valueIndex < valueProjName.length; valueIndex++) {
g_form.addOption('application_name', values["Business User"].u_project_code[valueIndex], valueProjName[valueIndex]);
}
 
var valueEnvironmentName = values["Business User"].u_environment_team_name;
for (var buEnvironmentIndex = 0; buEnvironmentIndex < valueEnvironmentName.length; buEnvironmentIndex++) {
g_form.addOption('environment', values["Business User"].u_environment_teams_code[buEnvironmentIndex], valueEnvironmentName[buEnvironmentIndex]);
}
 
var pdValueProjName = values["Product Development"].u_project_name;
for (var pdValueIndex = 0; pdValueIndex < pdValueProjName.length; pdValueIndex++) {
g_form.addOption('department_teams_area', values["Product Development"].u_project_code[pdValueIndex], pdValueProjName[pdValueIndex]);
}
 
var pdValueEnvironmentName = values["Product Development"].u_environment_team_name;
for (var pdEnvironmentIndex = 0; pdEnvironmentIndex < pdValueEnvironmentName.length; pdEnvironmentIndex++) {
g_form.addOption('safe_teams', values["Product Development"].u_environment_teams_code[pdEnvironmentIndex], pdValueEnvironmentName[pdEnvironmentIndex]);
}
 
    }
}
 
I need some inputs that why for people with no roles this error is happening.
Any insights would be helpful!
 
9 REPLIES 9

Appu2
Tera Contributor

Here is the script include I created. If you could find any error in code happy to update it.

var KPMG_nTAAPDetails = Class.create();
KPMG_nTAAPDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    retrieveDetails: function() {
        var targetTable = 'u_ntaap_mapping';
        var initialField = 'u_user_access_type';
        var otherFields = ['u_project_name', 'u_project_code', 'u_environment_team_name', 'u_environment_teams_code', ];

        var initialGlideAggregate = new GlideAggregate(targetTable);
        initialGlideAggregate.addEncodedQuery('u_ntaap_version=2.0');
        initialGlideAggregate.addNotNullQuery(initialField);
        initialGlideAggregate.groupBy(initialField);
        initialGlideAggregate.query();

        var uniqueValuesMap = {};
        var initialValuesArray = [];
        var roleValuesMap = {};

        while (initialGlideAggregate.next()) {
            var initialValue = initialGlideAggregate.getValue(initialField);

            if (initialValuesArray.indexOf(initialValue.toString()) === -1) {
                initialValuesArray.push(initialValue.toString());

            }

            var uniqueValuesForOtherFields = {};
            for (var i = 0; i < otherFields.length; i++) {
                var otherField = otherFields[i];
                var otherFieldValues = [];

                var otherGlideRecord = new GlideRecord(targetTable);
                otherGlideRecord.addQuery(initialField, initialValue);
                otherGlideRecord.query();

                while (otherGlideRecord.next()) {
                    var otherValue = otherGlideRecord.getValue(otherField);
                    if (otherValue && otherFieldValues.indexOf(otherValue.toString()) === -1) {
                        otherFieldValues.push(otherValue.toString());
                    }
                    if(otherField === "u_environment_teams_code") {
                        var recordRoleName = otherGlideRecord.getValue("u_role_name");
                        var recordRoleCode = otherGlideRecord.getValue("u_role_code");
                        if (Object.keys(roleValuesMap).indexOf(otherValue.toString()) !== -1){
                            roleValuesMap[otherValue.toString()].push({
                                u_role_name: recordRoleName, u_role_code: recordRoleCode
                            });
                        } else {
                            roleValuesMap[otherValue.toString()] = [
                                {u_role_name: recordRoleName, u_role_code: recordRoleCode}
                            ];
                        }
                    }
                }
                uniqueValuesForOtherFields[otherField] = otherFieldValues;
            }
           
            uniqueValuesMap[initialValue] = uniqueValuesForOtherFields;
            var uniqueValueMapping = JSON.stringify(uniqueValuesMap, null, 2);

        }
        var finalvalueArray = {
            initialValuesArray: initialValuesArray,
            uniqueValuesMap: uniqueValuesMap,
            roleValuesMap: roleValuesMap
        };
        return JSON.stringify(finalvalueArray, null, 2);

    },

    type: 'KPMG_nTAAPDetails'
});

I doubt there's an error in the script itself, since it works for some users, so the issue is that unrolled users can't call it, likely due to an ACL on the Script Include.

soumyagupta
Tera Contributor

Hi,

Provide snc_internal or public role to ACL of client callable script include.

I faced similar and it solved the issue.

Appu2_0-1696598956789.png

These 2 only I can see. which one to give?

Appu2
Tera Contributor

Providing the Public role to Client Callable SI worked! Thank you