Get User by UserID

prashant_gadgil
Tera Contributor

in an UI action, I am trying to get User Object for the engineer selected by the user in the engineer field on the form.

var engUserID = current.engineer.user_name;
var thisUser = gs.getUser();
var engineerUser = thisUser.getUserByID(engUserID);

But it is giving error "Cannot find function getUserByID in object com.glide.script.fencing.ScopedUser"

Later I want to check if engineerUser is in some specific role..

How do I go about doing this validation or is there any other API I can use.

 

Thanks in advance for any help

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Prashant,

It won't work in scoped app.

can you tell what is your requirement?

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

User will be submitting a new request in a scoped app. One of the fields he will select is Engineer for this request who will approve it. So Engineer field on the form is a reference field to Sys User table. Since I can't put constraint on which user he will select from the many users, before submitting the request, in Submit Request UI Action, I want to check if the engineer selected has a particular role.... hence in my script above, i will be doing hasRole check on the engineerUser object.

 

But I can't get to that object due to this limitation of scoped app GlideUser API.

 

ggg
Giga Guru

you can write a display BR and set g_scratchpad.xxx with any data you need.

then use g_scratchpad.xxx in your UI Action.