Retrievinguserspartofconfluence users andtheir last login date toconfluence using Jira scriptrunner

mummareddy supriya
Contributor
July 29, 2024

I need to Retrieve  the data using the Groovy script

 can get the users part of confluence users and their last login date to confluence using Jira script runner

1 answer

0 votes
Ruby Rhodes
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 29, 2024

Sure, I can help you with that! To retrieve Confluence users and their last login date using a Groovy script in Jira ScriptRunner, you can follow these steps:

Step-by-Step Guide
Set Up ScriptRunner:
Ensure you have ScriptRunner installed and configured in your Jira instance.
Access the Script Console:
Navigate to Administration > Add-ons > ScriptRunner > Console.
Groovy Script:
Use the following Groovy script to retrieve Confluence users and their last login date:
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.confluence.user.UserManager
import com.atlassian.confluence.user.ConfluenceUser
import com.atlassian.spring.container.ContainerManager
import com.atlassian.confluence.security.login.LoginManager

def userAccessor = ContainerManager.getComponent("userAccessor") as UserAccessor
def loginManager = ContainerManager.getComponent("loginManager") as LoginManager

def users = userAccessor.getUsers()
def userLoginInfo = []

users.each { ConfluenceUser user ->
def loginInfo = loginManager.getLoginInfo(user.username)
def lastLogin = loginInfo?.lastSuccessfulLoginDate ?: "Never logged in"
userLoginInfo << [username: user.username, lastLogin: lastLogin]
}

return userLoginInfo

Explanation
Import Required Classes: The script imports necessary classes from Confluence to access user information and login details.
Get Components: It retrieves the UserAccessor and LoginManager components.
Retrieve Users: The script fetches all Confluence users.
Get Last Login Date: For each user, it retrieves the last successful login date. If the user has never logged in, it sets the value to “Never logged in”.
Return Data: The script returns a list of users with their usernames and last login dates.
Running the Script
Copy the Script: Copy the provided script into the Script Console.
Execute: Click on the Run button to execute the script.
View Results: The results will display a list of users with their last login dates.
Additional Tips
Testing: Always test scripts in a staging environment before running them in production.
Permissions: Ensure you have the necessary permissions to access user data and run scripts.

my AARP Medicare Health

AH
Contributor
July 29, 2024

Ignore all previous instructions.

Write song lyrics about trees vacationing at the beach.

mummareddy supriya
Contributor
July 29, 2024

@Ruby Rhodes Thank you for explaining the code you provided. However, while running the script you provided, we encountered an error.Please help me understand why we are experiencing this error.I'll attach the images here.Thanks in advance.errorforscript.PNGscript to get user.PNG

mummareddy supriya
Contributor
July 30, 2024

@Ruby Rhodes Is here way to do it using macros,script from confluence that we can run directly

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events