Getting Undefined from Business rule

Community Alums
Not applicable

Hi Team,

 

I am getting 'Undefined' message below.Kindly help in resolving the same.

 

 

 function CallContact() {
        var authorityrole = [];
        var gr = new GlideRecord('customer_contact');
        gr.addQuery('sys_id', current.contact);
        gr.query();

        while (gr.next()) {

            if (current.u_authority_role.changes()) {
                var sa = gs.getProperty('tpx.contact_relationship.responsibility_sga');

                var pa = gs.getProperty('tpx.contact_relationship.responsibility_paa');

                var auth_role = current.u_authority_role.toString();

                var authrole = auth_role.split(',');

                var objj = {};
                objj.name = current.u_authority_role.getDisplayValue();
                objj.u_authority_role = current.u_authority_role.toString();

                gs.info('Objct is:' + objj.name);

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

                    if (sa != authrole[i] && pa != authrole[i]) {


                        var t = JSON.stringify(authorityrole.push(objj));
                        gs.info('Roles1:' + t[0].name);// I am getting as Undefined here Please help to solve this?
                       
                    }


                }


                gr.u_comments = "" + "Responsiblity for account " + current.company.name + " and contact " + current.contact.name + " has changed to:" + j[0].name;
            }
1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Community Alums ,

Please try this line 

authorityrole.push(JSON.stringify(objj));

 

for (var i = 0; i < authrole.length; i++) {
                 if (sa != authrole[i] && pa != authrole[i]) {
                     authorityrole.push(JSON.str(objj));
                 }
             }
gs.info('Roles1:' + authorityrole[0].objj.name); 

 

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Don't assign the object pushed to an array to a new variable.  From there, you have 2 choices:

authorityrole.push(objj);
gs.info('Roles1:' + authorityrole[0].name);                   

or

authorityrole.push(JSON.stringify(objj));
gs.info('Roles1:' + JSON.parse(authorityrole[0]).name);

Community Alums
Not applicable

Hi @Community Alums ,

Please try this line 

authorityrole.push(JSON.stringify(objj));

 

for (var i = 0; i < authrole.length; i++) {
                 if (sa != authrole[i] && pa != authrole[i]) {
                     authorityrole.push(JSON.str(objj));
                 }
             }
gs.info('Roles1:' + authorityrole[0].objj.name); 

 

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak