Auto Populate User Details through Different Methods
Populate User Details through Different Methods
First method
The simplest way to display user details depending on another variable is via the auto-populate feature in the variable form. This feature was introduced in Utah release.
Another simple way to populate user details is by using JavaScript filters like this:
- javascript:gs.getUserID(); // user sys_id
- javascript:gs.getUserName(); // user name
- javascript:gs.getUser().getEmail(); // user email address
These filters will populate the logged-in user's sys_id, user name, and email address.
To make it work you need to insert these into the default value field of the respective variables.
References:
- https://www.servicenow.com/community/developer-forum/how-to-auto-populate-fields-for-logged-in-user/m-p/1962339/page/3
- https://www.youtube.com/watch?v=8jvrvdx5F2Y&ab_channel=ServiceNerd
Second method
Another way to populate user details is by using Client Scripts.
Example:
function onLoad() {
var currentUser = g_user.userID; // save logged-in user sys_id in currentUser
if (g_form.isNewRecord()) // check if form is for new record{
g_form.setValue('caller_id', currentUser);
}
}
function onLoad() {
var currentUser = g_user.userID; // save logged-in user sys_id in currentUser
if (currentUser != '') // check if logged-in user is not empty{
g_form.setValue('caller_id', currentUser);
}
}
This method is for having more control over when to populate the user details.
You can also do it via UI Policies & UI Actions of course.
References:
- https://www.youtube.com/watch?v=datpHpPj6bE&ab_channel=SAASWITHSERVICENOW
- https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0745287
- https://www.reddit.com/r/servicenow/comments/egewz2/autopopulate_email_field_from_name_field_in_new/
- https://www.servicenow.com/community/itsm-forum/time-worked-autofill-user-by-logged-in-user/td-p/586606
Third method
If you really want to go Berzerk you can go for the AJAX API to populate user attributes.
Note: this method goes usually hand in hand with Catalog Client Scripts (see Second Method).
References:
- https://www.servicenow.com/community/developer-articles/auto-populate-user-details-using-ajax/ta-p/2315390
- https://www.servicenow.com/community/virtual-agent-forum/autopopulate-the-group-member-when-group-is-selected-in-catalog/m-p/2848043
- https://www.servicenow.com/community/guided-learning-itsm/when-user-is-selected-then-auto-populate-the-groups-that-user-is/td-p/2601558/page/1
- https://www.servicenow.com/community/guided-learning-itsm/i-want-to-auto-populate-the-user-details-based-on-the-user/m-p/2802008/page/2
- https://www.servicenow.com/community/itsm-forum/populate-groups-and-roles-based-on-selected-user/m-p/2499263
- https://www.servicenow.com/community/developer-forum/need-to-populate-the-group-names-which-opened-by-user-belongs-to/m-p/1537662
- https://docs.servicenow.com/bundle/vancouver-platform-administration/page/administer/field-administration/concept/c_AutoCompleteForReferenceFields.html
- https://www.youtube.com/watch?v=jAAClJ0Ld6o&ab_channel=TechnoMonk
- https://www.youtube.com/watch?v=MgXuzjNAei8&ab_channel=LearnServiceNowwithRavi
Fourth method
Another method is to use the GlideUser API.
Reference:
- https://www.servicenow.com/community/developer-blog/quot-fpcuser-quot-a-more-useful-user-object/ba-p/2265928
Fifth method
Since Utah release, there has been a new auto-populate functionality that makes things even easier to populate user details.
Note: this functionality only applies to catalog item variables.
References:
- https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-reference-type-variable-utah/ta-p/2475511
- https://www.youtube.com/watch?v=qT8gHMObuJQ&ab_channel=NayeemServiceNowBlog
NOTE:
The above methods are all about auto-populating user details when a FORM is loading.
There is also the other way around whereby auto-population of info is done by submitting an incident or request from the Service Portal.
Reference:
- https://www.servicenow.com/community/developer-articles/auto-populate-quot-contact-type-quot-field-to-quot-self-service/tac-p/2766723
Comments
Post a Comment