How to get user full name from user id

tsoct
Tera Guru

In Performance analytic, I need to get the full name of the agent from the created_by field. And the script below doesn't seem work.

Any idea why?

function getUser(userName) {

        var grUs = new GlideRecord('sys_user');

        grUs.get('name',userName);

        return grUs.getValue('sys_id') || '';

}

getUser(current.jour_sys_created_by);

**created_by is a string, not reference. Hence I am unable to use getDisplayValue.

**example: User id = admin; Full name = System administrator

1 ACCEPTED SOLUTION

Kannan Nadar
Tera Guru

Hey,



The created_by field would be storing the user name and not the name. So your script should be like below.



function getUser(userName) {


        var grUs = new GlideRecord('sys_user');


        grUs.get('user_name',userName);


        return grUs.getValue('sys_id') || '';


}


getUser(current.jour_sys_created_by);


View solution in original post

7 REPLIES 7

Kannan Nadar
Tera Guru

Hey,



The created_by field would be storing the user name and not the name. So your script should be like below.



function getUser(userName) {


        var grUs = new GlideRecord('sys_user');


        grUs.get('user_name',userName);


        return grUs.getValue('sys_id') || '';


}


getUser(current.jour_sys_created_by);


Thanks Kannan! You are awesome!


Harish KM
Kilo Patron
Kilo Patron

gs.getUser().getFullName();// this will give full name


http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0


Regards
Harish

Gowrisankar Sat
Tera Guru

Hi,



What value is created_by displaying, email or username?



There is a scope that value in the created_by be truncated as it is a string field.