logo

NJP

Auto Populate User Details through Different Methods

Import · Dec 04, 2023 · article

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:

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:

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:

Another method is to use the GlideUser API.

Reference:

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:

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:

View original source

https://www.dancovic.com/2023/12/auto-populate-user-details-through.html