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.

getUniqueValue how does it work to return users?

gunishi
Tera Guru

Hi all, 

 

I have the following code which works as intended, but I don't fully understand why.  The function takes in a user, finds their manager and then returns a list of all the users said manager manages. Why/how does the code in red/bold return the users?

 

getReportee: function(user){

    var manager;

    var gr = new GlideAggregate('sys_user');

    gr.addQuery('sys_id', user);

    gr.query();

    if (gr.next()){

        manager = grgetValu('manager');

    }

    var grTwo = new GlideRecord('sys_user');

    grTwo.addQuery('manager', manager);

    grTwo.query();

    var user = []

    while (grTwo.next()){

        users.push(grTwo.getUniqueValue());

    }

    return users.toString();

}

 

Thank you!

 

G

1 ACCEPTED SOLUTION

Adrian Ubeda
Mega Sage

Hello gunishi, 

getUniqueValue returns the primary key of the record, in other words the sys_id of the record. Inside your second loop you are iterating over sys_user table, that's why users arrays will show you a list of user's sys_id. 

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

View solution in original post

3 REPLIES 3

sushma9
Tera Contributor

Hi Gunishi,

 

getUniqueValue() :  it will not accept any arguments and It is will  only return the sys id .

Please find the below link to know more about the this.

https://developer.servicenow.com/dev.do#!/reference/api/utah/client/c_GlideFormAPI#r_GlideFormGetUni...

 

Adrian Ubeda
Mega Sage

Hello gunishi, 

getUniqueValue returns the primary key of the record, in other words the sys_id of the record. Inside your second loop you are iterating over sys_user table, that's why users arrays will show you a list of user's sys_id. 

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

Hi Adrian, 

 

Thank you for this, it was exactly the explanation I was looking for!

 

G