e.g. 'employee'
It is also very simple to get user information even if the attribute you want to retrieve is not listed above by using a ‘gs.getUser().getRecord()’ call as shown here…
The g_user object can be used only in UI policies and Client scripts. Contrary to its naming, it is not truly a user object. g_user is actually just a handful of cached user properties that are accessible to client-side JavaScript. This eliminates the need for most GlideRecord queries from the client to get user information (which can incur a fairly significant performance hit if not used judiciously).
Property/Method | Return value |
---|---|
g_user.userName | User name of the current user e.g. employee |
g_user.firstName | First name of the current user e.g. Joe |
g_user.lastName | Last name of the current user e.g. Employee |
g_user.userID | sys_id of the current user e.g. 681ccaf9c0a8016400b98a06818d57c7 |
g_user.hasRole() | True if the current user has the role specified, false otherwise. ALWAYS returns true if the user has the 'admin' role. Usage: g_user.hasRole('itil') |
g_user.hasRoleExactly() | True if the current user has the exact role specified, false otherwise, regardless of 'admin' role. Usage: g_user.hasRoleExactly('itil') |
g_user.hasRoles() | True if the current user has at least one role specified, false otherwise. Usage: g_user.hasRoles('itil', 'admin') |
It is often necessary to determine if a user is a member of a given group from the client as well. Although there is no convenience method for determining this from the client, you can get the information by performing a GlideRecord query. Here’s an example…
To get any additional information about the currently logged-in user from a client-script or UI policy, you need to use a GlideRecord query. If at all possible, you should use a server-side technique described above since GlideRecord queries can have performance implications when initiated from a client script. For the situations where there’s no way around it, you could use a script similar to the one shown below to query from the client for more information about the currently logged in user.
There are quite a few documented examples of some common uses of these script methods. These scripts can be found on the ServiceNow docs site .
Mark Stanger
Date Posted:
June 23, 2021
Share This:
Thanks for the great tips… My personal favorite:
gs.getUser().getRecord().getValue(‘title’);
never knew you could do that, awesome!
I was looking for a way to get the default set to the User Time Zone. Looked everywhere and it was on my favorite site..!
javascript:gs.getUser().getRecord().getValue(‘time_zone’);
Note that if you use this method, and you have the time zone selector turned on, you may run into issues. The time zone selector sets the User’s Session TZ, but not their default.
For more consistent results, use the following: var tzStr = gs.getSession().getTimeZoneName(); // “US/Pacific” var jTZ = gs.getSession().getTimeZone(); // sun.util.calendar.ZoneInfo java object. APIDoc linked below
Java doc ZoneInfo api: http://www.docjar.com/docs/api/sun/util/calendar/ZoneInfo.html
Thank you for the great work… finally one place to get the information about the UserObject stuff…
Just one note:
– the hasRole() returns true, if the user has the role specified (e.g. hasRole(role)) OR the admin role.
– to get a true/false for a specific role, use hasRoleExactly(role), which will only return true, if the user has the itil-role.
Thanks for the feedback. This method had some issues in the past (which is why I didn’t include it). It looks like it’s in the official ServiceNow doc now though so hopefully I’m safe in including it here :). I just added it to the article above.
I looked at the Usage example for “isMemberOf()” and also checked the wiki article for the function “getUserByID” ( http://wiki.servicenow.com/index.php?title=Getting_a_User_Object&redirect=no#Method_Detail ) but I cannot get it to work.
Is this function maybe retired?
Some code I played with is:
I’m not having any luck with it either. I haven’t heard of it being retired, but you’ll probably need to contact ServiceNow support to see. Please post back here with your findings.
Here we go: first we have to initialize a variable with “getUser()”. After that we can get any user object using it’s sys_id or UserID. Below the updated code to make the example work:
Thanks Andreas! I’ve updated the table above with this solution.
is it possible to check whether he/she is one of the member of Assignment group? Please guide me friends.
Yes. Check out ‘isMemberOf’ above.
sorry Mark. i forget to mention, is it possible to do this in client script?
Not directly. You could easily do a client-side GlideRecord query against the ‘sys_user_grmember’ table to find that though. Just make sure to do an asynchronous gliderecord query with a callback. You can find an example of this type of script here… https://servicenowguru.com/scripting/client-scripts-scripting/gform-getreference-callback/
Thanks Mark.
Thanks for all the info, very handy and interesting indeed. One question though, is there a method like the var hasRoleExactly that will work server-side? I can get it to work okay client-side but that’s it.
Thanks Martin
I don’t know of any built-in way of doing this, but you could always query the ‘sys_user_has_role’ table directly or create an on-demand script include that would allow you to call it in a shorthand way.
Thanks Mark, I thought that might be the alternative :)
How does one get the client’s business number? The wiki shows how to get the mobile number, but not the business number.
http://wiki.servicenow.com/index.php?title=Getting_a_User_Object
Up above I explain for both back-end and client-side code how you can get any attribute even if there’s not a specific function defined. You can get any attribute from the back-end like this. gs.getUser().getRecord().getValue(‘title’);
If I understand that correctly, then I could use this in a script of a workflow that works on a condition of an incident being submitted, to set the value of phone for the incident, to the user’s business phone, with the following script?
current.u_cos_contact_no = gs.getUser().getRecord().getValue(‘phone’);
Correct. As long as ‘phone’ is the name of the field you want to pull the value from.
On my incident form, “Contact Phone” variable is called u_cos_contact_no.
In my client’s user form, “Business Phone” variable is called phone.
For my workflow, would I want to do a custom script, or simply put do a Set Values, and then use javascript:gs.getUser().getRecord().getValue(‘phone’) ?
An update, I made a script step in the workflow, and the following works in my system:
var businessphone = gs.getUser().getRecord().getValue(‘phone’); current.u_cos_contact_no = businessphone;
Now to try it as a Set Value step in the workflow, with javascript:gs.getUser().getRecord().getValue(‘phone’); Not sure if it will work, but it’s work a shot to eliminate extra steps in the workflow.
Sorry to keep filling this up, but I can’t figure out how to edit my previous post.
On further testing, javascript:gs.getUser().getRecord().getValue(‘phone’) does work in a Set Value step of the workflow, however it pulls the phone number of the user logging in the incident, not the phone number of who the “client” has been set to for the incident. Any way to modify this?
Much thanks Mark
I wanted to know if we could access the company of the user involved, using the g_user field.
Thanks and Regards, Vivek
Sure. Take a look at the ‘title’ example at the bottom of the article. It shows how you can use a GlideRecord query to get any additional information about the user (including company) that you want.
These articles are so helpful, thank you Mark for making this public information.
Extremely helpful, thank you, Mark!
Thank you for the awesome tips! Your whole website is fantastic. :-)
Article still relevant after 13 years. Amazing !
Comments are closed.
Achim says:
Jacob Kimball says:
Fresh content direct to your inbox.
Just add your email and hit subscribe to stay informed.
Since 2009, ServiceNow Guru has been THE go-to source of ServiceNow technical content and knowledge for all ServiceNow professionals.
© Copyright 2009 – 2024 | All Rights Reserved
Get full access to ServiceNow: Building Powerful Workflows and 60K+ other titles, with a free 10-day trial of O'Reilly.
There are also live events, courses curated by job role, and more.
Assignment Rules are a simpler alternative to Data Lookup. While Data Lookup is very powerful, allowing you to set any field, it does involve a quite a bit of configuration, including creating a new table.
In contrast, an Assignment Rule uses the simpler condition builder to specify when it should run. If it matches, then it'll either populate the Assigned to and Assignment group fields with a hardcoded value, or you can use a script. We have got the group we want to use in a property, so this option is perfect. Follow these steps:
Get ServiceNow: Building Powerful Workflows now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.
Get Mark Richards’s Software Architecture Patterns ebook to better understand how to design components—and how they should interact.
Dive in for free with a 10-day trial of the O’Reilly learning platform—then explore all the other resources our members count on to build skills and solve problems every day.
ServiceNow Advanced Reference Qualifier | How to filter the Assignment group based on Assigned To
Been in a predicament in ServiceNow, where you know the person a task needs to be assigned to, but don’t know the right group? I got you!
In this video, we add an advanced reference qualifier on a dictionary override on the assignment group fields (for incidents) that calls a server side script include to run some funky glideRecord queries and return as back a refined list of group sys_id’s. Its then these groups that are shown when you click the Assignment Group magnifying glass.
https://docs.servicenow.com/en-US/bundle/tokyo-platform-administration/page/script/server-scripting/concept/c_ReferenceQualifiers.html
https://www.servicenow.com/community/developer-forum/dynamic-advanced-reference-qualifier-examples/m-p/1386576
javascript:new global.AssignmentGroupFilter().refineAssignmentGroup(current.assigned_to)
Tags: advanced reference qualifier beth anglin GlideRecord reference field reference qualifier script include servicenerd servicenow admin servicenow demo servicenow tutorial sysid in
ServiceNow: How to embed hyperlinks in work notes | clickable links
All Videos / New Features / Tips & Tricks
AI in ServiceNow with Justin Meadows | What does it mean?
February 27, 2023
New Features / Tips & Tricks
What is ChatGPT and Can We Use it for ServiceNow
December 18, 2022
ServiceNow Process Automation Designer (PAD) | What does it do?
December 19, 2023
All Videos / Flow Designer
“Do the Following Until” Flow Logic in ServiceNow Flow Designer
September 1, 2023
Exploring Dynamic Flow and Get Flow Output Logic in ServiceNow Flow Designer!
July 24, 2023
All Videos / Flow Designer / Tips & Tricks
Flow Designer Error Handling ServiceNow | How to…
July 3, 2023
June 11, 2023
Service Catalog / Tips & Tricks
October 30, 2022
Integrations
ServiceNow Inbound REST API | Import Set API
September 12, 2022
New Features / Shorts
ServiceNow San Diego Polaris | ServiceNow Next Experience UI #SanDiego #Polaris #Shorts
February 7, 2022
Flow Designer
ServiceNow Flow Template Builder | Create a template using Flow Template Builder
October 6, 2022
Subreddit for ServiceNow users, admins, devs, platform owners, CTOs and everything in between.
No plain hardcoded userID scripting but want to do via catalog or flow designer so that selection of users is part of the UI, any idea please
By continuing, you agree to our User Agreement and acknowledge that you understand the Privacy Policy .
You’ve set up two-factor authentication for this account.
Create your username and password.
Reddit is anonymous, so your username is what you’ll go by here. Choose wisely—because once you get a name, you can’t change it.
Enter your email address or username and we’ll send you a link to reset your password
An email with a link to reset your password was sent to the email address associated with your account
Dashboards Dashboards & Wallboards PCCE Self-Hosted ServiceNow UCCE UCCX Wallboards
July 2024 – The following is a list of feature updated that have recently been introduced and added to the ServiceNow Connector for 2Ring Dashboards & Wallboards. If you would like a detailed overview of the newest features, you can schedule a demo with a 2Ring product expert here . For any support and upgrade related queries, you can access a full list of contacts here .
Adding support for OAuth authentication.
Adding support for “REST Aggregate API” from ServiceNow for enhanced support of custom calculations.
Task List Grid:
Task State KPI now also offers these parameters:
Parameters “Priority” and “State” now receive values from ServiceNow – so options are available as checkboxes for selection in 2Ring interface.
Share 2Ring’s content with others on your favorite platforms!
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Get early access and see previews of new features.
How to generate report in servicenow to display list of all ticket (regardless of ticket type and current status & current assigned group) WHICH are assigned to my group/team member OR in other words, listing of all ticket on which my team member worked regardless of current assigned to or state.
I want to see all incidents opened last month that were assigned to my groups at some time
You can find whether an incident was assigned to a user from record history. You can write a script to filter the history on "assigned to" and then check if the user belongs to your team.
Replace XXXXX by your domain name to get the report
https://XXXXX.service-now.com/task_list.do?sysparm_query=assignment_group%3Djavascript%3AgetMyGroups()%5Eactive%3Dtrue%5Eassignment_group.typeLIKE7aab6a7895121000f9acb7a2692bd189%5EGROUPBYassigned_to&sysparm_first_row=1&sysparm_view=
Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more
Post as a guest.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .
COMMENTS
Loading... Loading...
*Disclaimer: We are reviewing video content for Accessibility standards*How to determine your own, or a colleague's, assignment group.
As you can see in your image the information for the groups is stored in table sys_user_group. The information which users are assigned to which group is stored in table sys_user_grmember. So the REST query could be a GET to this URL:
Create an assignment group - Product Documentation: Utah - Now Support Portal.
Here are ten different methods to find the sys_id of a record in ServiceNow: Right-click or hamburger. You can right-click the header bar of most forms and find the sys_id. To get a sys_id from the header bar: Navigate to the record where you are looking for a sys_id. Right-click the header bar and select Copy sys_id.
Learn how to use the GlideUser API to get the groups that the current user belongs to in ServiceNow.
I want to update the assignment group to a particular assignment group when the condition fulfills on RITM ie. service offering is xyz and location is abc, then it should update. For example, there is one catalog item that is being raised by GETit and RITM is generated with an assignment group. I want to update that value when the matching ...
This ServiceNow tutorial will demonstrate how to add users to an assignment group in ServiceNow. Specifically, it will demonstrate how to add user to Service...
To create groups, use the All menu in the main ServiceNow browser window (not Studio) to open User Administration > Groups. Click the New button. Configure the group: Name: Name of the group. Manager: Group manager or lead. Group email: Group email distribution list or the email address of the group's point of contact, such as the group manager.
Please take note of the following points while integrating ServiceNow and IG for fulfillment: 1) Please modify the default Request Form in ServiceNow to have the Assignment Group visible. By default, it is not visible. The assignment will be showed if export the form to csv for pdf. ServiceNow admin will know how to accomplish this.
Usage. gs.getUser () Returns a reference to the user object for the currently logged-in user. var userObject = gs.getUser (); gs.getUserByID () Returns a reference to the user object for the user ID (or sys_id) provided. var userObject = gs.getUser ().getUserByID ('employee'); gs.getUserName () Returns the User ID (user_name) for the currently ...
We have got the group we want to use in a property, so this option is perfect. Follow these steps: Navigate to System Policy > Rules > Assignment, and click on New. Use the following values, and Save. Name: Assign to External Team. Table: Maintenance [x_hotel_maintenance] ... Get ServiceNow: Building Powerful Workflows now with the O'Reilly ...
In this video, we add an advanced reference qualifier on a dictionary override on the assignment group fields (for incidents) that calls a server side script include to run some funky glideRecord queries and return as back a refined list of group sys_id's. Its then these groups that are shown when you click the Assignment Group magnifying glass.
The assignment group change on the change of the group membership of the user assigned to the record.
Some of it will come down to how you're configuring your groups, but I'd start with: Target table: sys_user_group. Conditions: Active is true, Type contains Assignment. 10. Reply. scarng. • 2 yr. ago. Navigator -> sys_user-group.LIST then you can filter and export. 5.
Loading... Loading...
Loading... Loading...
Award. Share. Machiavvelli3060. • 2 yr. ago. You'd need to put a collector variable on your catalog item in order to hold the values of the users you want to add. In your flow, you'll need to run script that queries the Group Has Member table and add a new record for each value input into the list collector variable. 2.
The requirement is to auto-populate the "Assignment Group" field present on the 'sc_req_item" table. Skip to page content Skip to chat. How to auto populate "Assignment Group" field present on the RITM record ['sc_req_item' table] - Support and Troubleshooting > Knowledge Base > Login here.
July 2024 - The following is a list of feature updated that have recently been introduced and added to the ServiceNow Connector for 2Ring Dashboards & Wallboards. If you would like a detailed overview of the newest features, you can schedule a demo with a 2Ring product expert here.For any support and upgrade related queries, you can access a full list of contacts here.
0. The easiest method that I found out is to go to Studio and go to your table. Show all records from table. There you create the filter with your conditions by clicking filter icon. Run the filter. Then copy query from created hyperlink (next to filter icon) with right click -> Copy query. You can also copy the whole URL.
How to generate report in servicenow to display list of all ticket (regardless of ticket type and current status & current assigned group) WHICH are assigned to my group/team member OR in other words, listing of all ticket on which my team member worked regardless of current assigned to or state. I want to see all incidents opened last month ...
Skip to page contentSkip to chat. Calculate the duration of an incident based on the Assignment Group. Most of the cases, the incident will be traversed to multiple teams for resolution. In such cases, if we want to calculate the duration.