-1

I want to get manager user from current user record. So i have created a for loop to get all the hierarchy from current users

Ex: if current current user Supervisor from my FORloop i will get the results like this

  • Asst manager
  • manager
  • VP
  • SVP
  • CEO

From above loop i need to separate Manager and VP users so that's why i added IF condition to my FOR loop but looks like it's not working

var grnewreports= new GlideRecord('sys_user');
grnewreports.get('2f78075c13d99a0085b9da82e144b0f5');
generateApprovalNewNonMangament(grnewreports,5,'test')

function generateApprovalNewNonMangament(grnewreports, approvalLevel, approvalDescription) {
    try {

        var approvalUser = '';
        var manager1level = '';
        //var manager = '';
        for(var i = 1; i <= approvalLevel ; i++) {

            approvalUser = grnewreports.manager;
            gs.log('approval user:'+approvalUser,'TESTINSIDEIF');
            grnewreports = grnewreports.manager; // upgrading the level of user so that in next loop it should pick next level

            if(string[i].title == 'Managemnt') {
                var manager1 = string[i];
                var vp = manager1.manager;
            }

        }

    }
    catch(ex) {
    }
}

Please help me where i am doing wrong in script

Thanks, Chaitanya

Kirk
  • 16,182
  • 20
  • 80
  • 112
  • I am passing user record in function and from For loop i am getting the user hierarchy all the way to CEO. In Hierarchy i need to separateManager, VP users and store them separate variables. Here is i am passing Sys Id of user record ----grnewreports.get('2f78075c13d99a0085b9da82e144b0f5'); – chaitanya kumar Aug 07 '17 at 21:48
  • I am passing user record in function and from For loop i am getting the user hierarchy all the way to CEO. In Hierarchy i need to separate Manager, VP users and store them separate variables. Here is i am passing Sys Id of user record ----grnewreports.get('2f78075c13d99a0085b9da82e144b0f5'); Above user is SUPVISOR and from FOR loop i will get the SYS ID s of ASST Manager, Manager, VP,SVP,CEO. From there i need to Extract the Manager , VP users from there that's why i added IF condition I am missing somethings in IF condition – chaitanya kumar Aug 07 '17 at 21:54
  • Is the misspelling of `Managemnt` intentional ... or should it be: **Management**? – Paul T. Aug 08 '17 at 00:50
  • I figured out the this issue. Have another question how do i declare array and keep the results from for loop into the array like from te above for loop i get the hierarchy of user and i want to store those results into array like this from for loop i get this Asst Mg, Manager, VP, SVP, CEO and i want to store them in like this [Asst Mg, Manager, VP, SVP, CEO]??? – chaitanya kumar Aug 09 '17 at 20:28
  • Are you trying to get an array of titles? It looks the loop and other handling is trying to get other info too? – Paul T. Aug 09 '17 at 22:07
  • I am trying to get users in array – chaitanya kumar Aug 16 '17 at 21:28

1 Answers1

0

I believe your issue might be due to "pass-by-reference".

Here's an article I wrote which explains the issue, and how to fix it! https://snprotips.com/blog/2017/4/9/always-use-getters-and-setters

The short answer: Use .getValue() on lines 13, 15, and 19!

Tim Woodruff
  • 600
  • 3
  • 9