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
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.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.