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.

Ref qualifier over list

Rosy14
Kilo Sage

Hi,

I have a list type field over sys_user table. I want to filter it so that it will show users with same company name as logged in user . below not working.

javascript:'company='+gs.getUserID().company;

2 ACCEPTED SOLUTIONS

Amit Verma
Kilo Patron
Kilo Patron

Hi @Rosy14 

 

Do you have the company set for the currently logged in user ? If you have recently set it up, you should logout and login again for gs.getUser().getCompanyID() to work. Refer below snips where it is working as expected for me :

 

AmitVerma_0-1709201231493.png

 

AmitVerma_1-1709201250933.png

 

AmitVerma_2-1709201273918.png

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

View solution in original post

swathisarang98
Giga Sage

Hi @Rosy14 ,

 

Try the below code but the catch here is you need to logout and then log in and retest as this is querying company field 

 

javascript:"company="+gs.getUser().getCompanyID();

 

swathisarang98_0-1709202005438.png

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

13 REPLIES 13

Nick Parsons
Mega Sage

The getUserID() method on GlideSystem returns a string, so it doesn't have a .company property. Instead, use gs.getUser().getCompanyID(); (using the javascript: prefix):

 

'company='+gs.getUser().getCompanyID();

 

it is not working. tried.

Can you explain what you mean by "not working" a bit more please - What it's doing instead? Is the dropdown not showing anything?

Also keep in mind that if you don't have a company set and recently set one on the user profile you're testing with, you may need to log in/out again to refresh your session.

Tai Vu
Kilo Patron
Kilo Patron

Hi @Rosy14 

Let's try the getCompanyID() to retrieve the current user's company sys_id.

 

Cheers,

Tai Vu

Rosy14
Kilo Sage

It is a list type field btw.