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
Your browser or one of your plugins is not allowing JavaScript to be run. This is a bummer since the ServiceNow Developers Site is dynamic and depends on JavaScript to function. If you want to visit this site, please disable the plugin, activate this site for JavaScript or use another browser.
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
Get full access to Learning ServiceNow 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.
The Assigned to [assigned_to] field is a reference field type that points to the Users [sys_user] table. This field is generally used to designate a user to work on, or be responsible for the task. By default, this field has a reference qualifier (role=itil) set on its dictionary record that prevents any non-itil user from being assigned to a task. You can override this reference qualifier on tables that extend task though, as the Project Task and Service Order tables do, if you have the relevant plugins installed.
The Assignment group [assignment_group] field serves pretty much the same purpose. The reason for having both, is that a workflow might automatically assign a certain type of task ticket to a group, ...
Get Learning ServiceNow 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.
Quick links, community champions.
Sign up to get the latest deals.
Discussion Forum and Stories
Indicates external site which may or may not meet accessibility guidelines
© 2024 Southwest Airlines Co. All Rights Reserved. Use of the Southwest websites and our Company Information constitutes acceptance of our Terms and Conditions . Privacy Policy Trademarks Do Not Sell/Share My Personal Information
IMAGES
VIDEO
COMMENTS
Loading... Loading...
Loading... Loading...
Create an assignment group - Product Documentation: Utah - Now Support Portal.
*Disclaimer: We are reviewing video content for Accessibility standards*How to determine your own, or a colleague's, assignment group.
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.
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:
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.; Parent: Other group of which this group is a member.The child group inherits the roles of the parent group. So, if a group has a parent, it inherits the roles of the parent group.
Probably one of the easiest traps people fall under is thinking that groups somehow align to departments. Work doesn't happen in silos, work is collaborative - therefore groups should be collaborative and cross functional. ServiceNow already has a department table structure for that purpose. 5) Don't Hardcode groups.
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 ...
In the case of the 'My Groups Work' module under the 'Service Desk' application there is a function called 'getMyGroups' that is used to identify task records where the assignment group value is one of the groups for which the current user is a member. The 'getMyGroups' function simply returns an array of group sys_id values for ...
A customer had the requirement to restrict a field referencing sys_users to only list active users who are members of a specific group.
answer = true; //Allow access if user has 'user_admin' role or is group manager. } Create ACL ('sys_user_grmember') The create ACL works a little bit differently because we don't have access to 'current.group.manager' before the record is created. Because of this, you need to open up create permissions to the role that your group ...
Returns a list of all groups that the currently logged-in user is a member of. var groups = gs.getUser().getMyGroups(); isMemberOf() Returns true if the user is a member of the given group, false otherwise. Takes either a group sys_id or a group name as an argument. gs.hasRole() Returns true if the user has the given role, false otherwise.
NOTE: You can learn more about lists, forms, and navigation in ServiceNow in the ServiceNow Basics learning module.. Groups. System Administrators can add roles to user records. If a role is applied to a small number of users, adding the role to User records is easily done. If a role needs to be applied to thousands of User records, it can be challenging to complete the process manually.
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:
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.
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.
Assigned to and Assignment group. The Assigned to [assigned_to] field is a reference field type that points to the Users [sys_user] table. This field is generally used to designate a user to work on, or be responsible for the task. By default, this field has a reference qualifier (role=itil) set on its dictionary record that prevents any non ...
The assignment group change on the change of the group membership of the user assigned to the record.
Have a business flight tomorrow that I purchased at least three weeks ago. Am A List Preferred ( have been preferred or A List for 10+ years), and confirmed this is reflected on my ticket. Imagine my shock when my boarding number came as B-47. So I guess, just wondering if anyone else has noticed th...
When there are multiple domains under a parent domain, assignment groups may need to be shared across these child domains. For example, say there are four parallel domains: TOP/A, TOP/B, TOP/C, TOP/D.
If you need to send out push notifications on mobile devices in addition to an email notification, for any event like task assigned to a group, or change commented on, this can be done through the following