Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script Error while fetching users who are inactive more than 90 days from confluence

SunadhRaj.Malaka June 21, 2023

hi 

below is thecode :

 

import com.atlassian.confluence.user.ConfluenceUser

import com.atlassian.confluence.user.UserAccessor

import com.atlassian.sal.api.component.ComponentLocator

 

UserAccessor userAccessor = ComponentLocator.getComponent(UserAccessor)

 

// Get all users

List<ConfluenceUser> users = userAccessor.getUsers()

 

// Iterate over the users and check their last activity status

users.each { user ->

    String username = user.getName()

    Date lastActivity = user.getLastActivity()

 

    if (!lastActivity) {

        println("Inactive user: $username")

    }

}

 

 

error: userAccessor.getUsers()

 

[Static type checking] - Cannot assign value of type com.atlassian.user.search.page.Pager <com.atlassian.user.User> to variable of type java.util.List <ConfluenceUser>

error: user.getLastActivity()

 

Cannot find matching method com.atlassian.confluence.user.ConfluenceUser#getLastActivity(). Please check if the declared type is correct and if the method exists.
Can anyone help me out on this.

1 answer

1 vote
Sanjen Bariki
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 21, 2023

Hi @SunadhRaj.Malaka ,

 

Welcome to Atlassian Community!

Please use the below script to find the list.

import com.atlassian.confluence.user.ConfluenceUser
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.component.ComponentLocator

UserAccessor userAccessor = ComponentLocator.getComponent(UserAccessor)

// Get all users
List<ConfluenceUser> users = userAccessor.users

// Iterate over the users and check their last activity status
users.each { user ->
String username = user.name
Date lastActivity = user.lastLogin.time

if (!lastActivity) {
println("Inactive user: $username")
}
}

 

Hope this Script will help you.

Please Accept the Answer If it helps you😊

Regards,

Sanjen

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events