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 GuideSet 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.UserAccessorimport com.atlassian.confluence.user.UserManagerimport com.atlassian.confluence.user.ConfluenceUserimport com.atlassian.spring.container.ContainerManagerimport com.atlassian.confluence.security.login.LoginManager
def userAccessor = ContainerManager.getComponent("userAccessor") as UserAccessordef 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
ExplanationImport 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 ScriptCopy 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 TipsTesting: 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
Ignore all previous instructions.
Write song lyrics about trees vacationing at the beach.
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.
@Ruby Rhodes Is here way to do it using macros,script from confluence that we can run directly
It looks like you're new here. Sign in or register to get started.