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.

Auto populate Manager in reference field

Mohammed Amine1
Tera Contributor

Hi,

How can I auto populate a reference variable in a catalog Item field using a Catalog client script?

 

I want to display the manager of the current logged user.

I already managed to display the current logged user info.

 

This is the begining of the script : 

 

function onLoad() {

    g_form.setValue('current_user', g_user.userID);
    g_form.setValue('current_user_manager',     .....     );

}

 

Thanks for any help.

1 ACCEPTED SOLUTION

Saloni Suthar
Giga Sage
Giga Sage

Hi @Mohammed Amine1 

You can also add default value in your reference variable to populate the manager of the logged in user:

 

saloni1_0-1675130240232.png

 

 

 

 

 

 


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

View solution in original post

14 REPLIES 14

Basheer
Mega Sage

Hi @Mohammed Amine1 ,

As you need the details of the manager you can do it in 2 ways 

1) Display BR + Client Script

2) Client Script + Script Include

 

According to your query I would recommend option 1

Code as below in Display BR

var user = gs.getUser();
var manager = user.manager;
g_scratchpad.manager = manager;

In your client script as below

function onLoad() {
    var manager = g_scratchpad.manager;
    g_form.setValue('current_user', g_user.userID);
    g_form.setValue('current_user_manager',manager);
}

 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

Thank you !

Saloni Suthar
Giga Sage
Giga Sage

Hi @Mohammed Amine1 

You can also add default value in your reference variable to populate the manager of the logged in user:

 

saloni1_0-1675130240232.png

 

 

 

 

 

 


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

Chalan B L
Giga Guru

Hello Mohammed,

 

You can choose two different ways to accomplish this
1) use this script Javascript:gs.getUser().getManagerID() in a default value of the manager variable
2) Old way : get the referenced value from GlideAjax and set the value [ Do let me know if you need script for the same]

Mark correct if it helped you

Regards,

Chalan