Work with Users

With HAPI, you can create scripts to gather lists of users based on different criteria and deactivate users.

Expanding on these scripts

You can use the methods outlined on this page with other HAPI methods.

Get user by name

To get a user by username and return their email address, enter a script like this in the Script Console:

Users.getByName('USERNAME').email

After you run this script, the user email is printed in the log: 

The HAPI script result, which is a list of emails.

Deactivate users

To deactivate a user, enter a script like this in the Script Console

Users.getByName('USERNAME').deactivate()

After you run this script, the user is deactivated. When you navigate to the Users screen, you can see the disabled flag next to the user: 

The HAPI script result, which is a list of users and ones that have been deactivated are noted.

Get inactive users

To get a list of inactive users, including deactivated users, use a script like this in the Script Console

import java.time.temporal.ChronoUnit
import java.time.Duration

Users.getInactiveUsers(Duration.of(90, ChronoUnit.DAYS)).collect { it.name }

After you run the script, you will have a list of users that have been inactive for 90 days.

The HAPI script result, which is a list of inactive users.

Customize the above script

You can change the period of inactivity by adjusting the Duration.of(90, ChronoUnit.Days)) to how long you need, like, Duration.of(6, ChronoUnit.DAYS)). Visit Oracle ChronoUnit documentation for help.

Get logged in user

To get the current logged in user, use a script like this in the Script Console

Users.getLoggedInUser()

After running this script, you get a list of users who are logged in: 

The HAPI script result, which is a list of users that are logged in.


Related pages

On this page