Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Unhandled Exeption in GlideAjax

Donabelle
Tera Contributor

Hi, I would like to ask what's wrong on my script, since it's showing JS error because of unhandled glideajax and the ESS Project Details are not populating.

 

Client Script: 

    // get ESS Project Details
    var gaGetProjectDetail = new GlideAjax('ESS_global_util');
    gaGetProjectDetail.addParam('sysparm_name', 'getESSProjectDetail');
    gaGetProjectDetail.addParam('projectSys_id', newValue);
    gaGetProjectDetail.getXML(setESSProjectDetails);


    function setESSProjectDetails(response) {
        var resp = response.responseXML.documentElement.getAttribute('answer');
        if (resp != '' || resp != null) {
           
            var fields = JSON.parse(resp);
            if (fields != '') {
                if (request_action == 'register_vlan_to_a_project') {
                    for (var j = 0; j < projectDetails.length; j++) {
                        g_form.setMandatory(projectDetails[j], false);
                        g_form.setDisplay(projectDetails[j], true);
                        g_form.setReadOnly(projectDetails[j], true);
                    }

                    // --- User Story 2546241: [ESS - Iteration 4.6] Update Request Action Permissions for Project Admin and Network Admin (CHG1747211)  By: "jeff.matthew.david" Date: 08/23/2023 --- //
                    if (role == 'projAdmin') {
                        g_form.setReadOnly('network_admin', true);
                    } else if (role == 'netAdmin' || role == 'essAdmin') {
                        g_form.setReadOnly('network_admin', false);
                    }
                    // --- End of User Story: 2546241--- //
                    //g_form.setMandatory('vlan_list',true);
                    g_form.setDisplay('vlan_list', true);
                    g_form.setValue('vlan_list', fields.vlan_list);

                } else if (request_action == 'modify_project_details') {
                    for (var i = 0; i < projectDetails.length; i++) {
                        g_form.setMandatory(projectDetails[i], true);
                        g_form.setDisplay(projectDetails[i], true);
                        g_form.setReadOnly(projectDetails[i], false);

                    }
                    g_form.setMandatory('business_unit', false);
                    g_form.setMandatory('project_id', false);
                    g_form.setReadOnly('project_id', true);
                    g_form.setDisplay('notification_recipients', true);
                    g_form.setDisplay('vlan_list_details', true);

                    if (role == 'projAdmin') {
                        g_form.setMandatory('network_admin', false);
                        g_form.setReadOnly('network_admin', true);
                    } else if (role == 'netAdmin' || role == 'essAdmin') {
                        g_form.setMandatory('project_admin', false);
                        g_form.setReadOnly('project_admin', true);
                        g_form.setReadOnly('network_admin', false);
                    }

                } else if (request_action == 'delete_nondelivery_center_project') {
                    for (var j = 0; j < projectDetails.length; j++) {
                        g_form.setMandatory(projectDetails[j], false);
                        g_form.setDisplay(projectDetails[j], true);
                        g_form.setReadOnly(projectDetails[j], true);
                    }
                    // --- User Story: 1420703 [ESS SP20] Update User List Format Change By: "adrian.alquin.hinlo"  Date: 06/18/2021 --- //
                    //                  g_form.setDisplay('proj_vlan_user_list',true);
                    //                  g_form.setReadOnly('proj_vlan_user_list',true);
                    g_form.setDisplay('vlan_user_list_deleteNDC', true);
                    g_form.setReadOnly('vlan_user_list_deleteNDC', true);
                }

                g_form.setValue('ess_project_sysid', fields.project_sysID);
                g_form.setValue('add_project_name', fields.add_project_name);
                // --- User Story: 1047444 Change By: "jessa.mae.n.alon"  Date: 4/16/2020 --- //
                g_form.setValue('project_id', fields.project_id);
                // --- End of User Story: 1047444 --- //
                g_form.setValue('project_name', fields.project_name);
               // g_form.setValue('geographic_unit', fields.geographic_unit);
                g_form.setValue('market_unit', fields.geographic_unit);
               // g_form.setValue('country', fields.country);
                g_form.setValue('countries', fields.country);
                g_form.setValue('facility_name', fields.facility_name);
                // essProjFacility: global variable to be used in ESS MRVS VLAN onChange vlan_name for validation
                essProjFacility = fields.facility_name;
                // --- User Story: 1388906 for more than 30 project admins Change By: "jessa.mae.n.alon"  Date: 05/13/2021 --- //
                var projAdminArr = fields.project_adminName.split(',');
                g_form.setValue('project_admin', fields.project_adminSys, projAdminArr);
                g_form.setValue('project_admin_second', fields.project_adminSys, projAdminArr);
                g_form.setValue('business_unit', fields.business_unit);
                g_form.setValue('organizational_unit', fields.organizational_unit);
                if (fields.notification_recipientsUser) {
                    var notifUserArr = fields.notification_recipientsUser.split(',');
                    g_form.setValue('notification_recipients', fields.notification_recipients, notifUserArr);
                }

                if (fields.network_admin == '' || fields.network_admin == undefined) {
                    g_form.showFieldMsg('network_admin', 'No Network Admin Group Mapping detected. Create a new Network Admin group specific for ' + fields.geographic_unit2 + ', ' + fields.country2 + ' and ' + fields.organizational_unit + '.', 'error');
                } else {
                    g_form.setValue('network_admin', fields.network_admin);
                    g_form.hideFieldMsg('network_admin', true);
                }



            }

        } else {
            alert('Error connecting to server');
        }
        // var gaMarket = new GlideAjax('ESS_global_util');
        // gaMarket.addParam('sysparm_name', 'getMarket');
        // alert("eeew" + test);
        // gaMarket.addParam('marketunit', g_form.getValue('geographic_unit'));
        // gaMarket.getXML(marketUnit);

        // function marketUnit(response) {
        //     var answer = response.responseXML.documentElement.getAttribute('answer');
        //     //var market2 = JSON.parse(answer);
        //     g_form.setValue('geographic_unit', answer);
        //     alert("booom" + g_form.getValue('geographic_unit'));
        // }
    }
 
 
And here is the server side script:
 getESSProjectDetail: function() {
        var recordID = this.getParameter('projectSys_id');
        var result = '';
        var approver = [];
        var obj = {};
        var projectDetails = new GlideRecord('x_amspi_clear_pass_ess_projects');
        projectDetails.addQuery('sys_id', recordID);
        projectDetails.query();
        if (projectDetails.next()) {
            obj.project_sysID = projectDetails.sys_id.toString();
            obj.add_project_name = projectDetails.add_project_name.toString();
            obj.project_name = projectDetails.project_name.toString();
            obj.project_id = projectDetails.project_id.toString();
            obj.project_adminSys = projectDetails.project_admin.toString();
            // --- User Story: 1388906 for more than 30 project admins Change By: "jessa.mae.n.alon"  Date: 05/13/2021 --- //
            if (projectDetails.project_admin.toString() != '') {
                obj.project_adminName = this.returnAdminUserName(projectDetails.project_admin);
            } else {
                obj.project_adminName = '';
            }

            obj.project_type = projectDetails.project_type.toString();
         //   obj.geographic_unit = projectDetails.geographic_unit.toString();
            obj.market_unit = projectDetails.geographic_unit.toString();
            obj.geographic_unit2 = projectDetails.geographic_unit.name.toString();
            obj.country = projectDetails.country.toString();
            obj.country2 = projectDetails.country.name.toString();
            obj.facility_name = projectDetails.facility_name.toString();
            obj.business_unit = projectDetails.business_unit.toString();
            obj.organizational_unit = projectDetails.organizational_unit.toString();
            obj.vlan_list = this.createVlanJson(recordID).toString();
            obj.additional_project_admin = projectDetails.additional_project_admin.toString();
            obj.notification_recipients = projectDetails.notification_recipients.toString();
            if (projectDetails.notification_recipients) {
                obj.notification_recipientsUser = this.returnAdminUserName(projectDetails.notification_recipients);
            }


            // --- User Story 2566251: [ESS - Iteration 4.6] Auto-populate Network Admin field for Delivery and Non-Delivery Center Projects (CHG1747211)  By: "jeff.matthew.david" Date: 08/23/2023 --- //
            if (projectDetails.network_admin.toString() != '') {
                obj.network_admin = projectDetails.network_admin.toString();
            } else {
                var gr = new GlideRecord('x_amspi_clear_pass_lts');
                //              gr.addEncodedQuery('country_location=' + projectDetails.country.toString() + '^organization=' + projectDetails.organizational_unit.toString() + '^NQorganization=' + projectDetails.organizational_unit.toString() + '^market_unit=' + projectDetails.geographic_unit.toString());

                if (country != '' && orgUnit != '') {
                    gr.addEncodedQuery('country_location=' + projectDetails.country.toString() + '^organization=' + projectDetails.organizational_unit.toString());
                } else if (market != '' && orgUnit != '') {
                    gr.addEncodedQuery('organization=' + projectDetails.organizational_unit.toString() + '^market_unit=' + projectDetails.geographic_unit.toString());
                } else {
                    gr.addEncodedQuery('sys_idISEMPTY');
                }

                gr.query();
                if (gr.next()) {
                    obj.network_admin = gr.sys_id.toString();
                }
            }
            // --- End of User Story: 2566251--- //
        }
        var data = JSON.stringify(obj);
        return data;
    },
 
 
0 REPLIES 0