No signature of method: com.atlassian.jira.user.util.UserUtilImpl.getUsers() is applicable for argum

prasad biddika
Contributor
June 12, 2023
Hi we are using DC the script is throwing error, please help with the same
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.event.AbstractEvent
import com.atlassian.crowd.event.user.UserCreatedEvent
import com.atlassian.jira.application.ApplicationAuthorizationService
import com.atlassian.jira.application.ApplicationKeys


UserUtil userUtil = ComponentAccessor.getUserUtil()

int licenses = 0

def CurrentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def applicationAuthorizationService = ComponentAccessor.getComponent(ApplicationAuthorizationService)

 
def total = 0
def output
def lstjson = []

 
userUtil.getUsers().each{ u ->
    if ((u.active) && (applicationAuthorizationService.canUseApplication(u, ApplicationKeys.SERVICE_DESK)))
    {
        //get the groups of the user
        def groupManager = ComponentAccessor.getGroupManager()
        def groupsNamesForUser = groupManager.getGroupNamesForUser(u)

        output='''{
        "user": "'''+u.emailAddress+'''",
        "displayName": "'''+u.displayName+'''"
        }'''

        licenses++
        lstjson.add(output)
    }
    def json= '''{ "items": '''+ lstjson +''' }'''
    log.warn("json"+json)

  File file = new File("//yourServerPath//licenses.json")
  file.write(json)
}

return licenses

2 answers

0 votes
Graham Twine
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 13, 2023

Hello @prasad biddika ,

 

What is the version of Jira DC and scriptrunner that this is implemented in?

 

Check what version of Jira you are using this in.

The latest document for User Util https://docs.atlassian.com/DAC/javadoc/jira/reference/com/atlassian/jira/user/util/UserUtil.html

 

The document for 7.1.9 is https://docs.atlassian.com/software/jira/docs/api/7.1.9/com/atlassian/jira/user/util/UserUtil.html

 

You can change the version to the version you are using, also not getAllApplicationUsers and getAllUsers

 

What are you trying to achieve with this script?

There are some things I see that can be improved. Unless you are going to extend the script further of course.

 

1. Do not load the group manager for each user. Load it before and use it for each user.

2. Only update the lstJson results inside the if condition

3. You may want to consider using the UserSearchService if the version of Jira has this included.

prasad biddika
Contributor
June 13, 2023

jira DCis 8.15.0 

prasad biddika
Contributor
June 13, 2023

I am expecting a script which shows total no of licenses used in Jira, Confluence , bitbucket, JSD and available licenses in all the applications

prasad biddika
Contributor
June 13, 2023

Application wise also ok

Graham Twine
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 13, 2023

What you have should work in Jira 8.15 so it is a little confusing.

I have the following returning a result in the console and adding a file to the home directory.



import groovy.json.JsonBuilder

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.application.ApplicationAuthorizationService
import com.atlassian.jira.application.ApplicationKeys

def userManager = ComponentAccessor.userManager

def applicationAuthorizationService = ComponentAccessor.getComponent(ApplicationAuthorizationService)

def serviceDeskUsers = []
def softwareUsers = []
def inactiveUsers = 0

def allUsers = userManager.allApplicationUsers.each { user ->
if (user.active) {
if (applicationAuthorizationService.canUseApplication(user, ApplicationKeys.SERVICE_DESK)) {

serviceDeskUsers.add([
"name": "${user.name}",
"email": "${user.emailAddress}",
"displayName": "${user.displayName}"
])
}
if (applicationAuthorizationService.canUseApplication(user, ApplicationKeys.SOFTWARE )) {

softwareUsers.add([
"name": "${user.name}",
"email": "${user.emailAddress}",
"displayName": "${user.displayName}"
])
}
} else {
inactiveUsers ++
}
}.size()

def items = new JsonBuilder([
'items':[
'licenses':[
'servicedesk':serviceDeskUsers.size(),
'software':softwareUsers.size()
],
'servicedesk':serviceDeskUsers,
'software':softwareUsers
]
]).toPrettyString()

new File("${System.getProperty('user.home')}/licensed-users.json").withWriter('utf-8') {
writer -> writer.write items
}

return "All Users: ${allUsers}
Inactive Users: ${inactiveUsers}
Service Desk: ${serviceDeskUsers.size()}
Software: ${softwareUsers.size()}"

 

Result

All Users: 8768768768768
Inactive Users: 876099087
Service Desk: 0
Software: 638888

 

prasad biddika
Contributor
June 13, 2023

The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script42.groovy: 54: token recognition error at: '\r' @ line 54, column 31. return "All Users: ${allUsers} ^ 1 error </pre>.

prasad biddika
Contributor
June 13, 2023

May I know which file we have to add in home directory? I am getting the above error when I run code in console

0 votes
Mohamed Benziane
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 13, 2023

Hi,

Can you give us the full error message you got please

prasad biddika
Contributor
June 13, 2023

Something went wrong: MissingMethodException

No signature of method: com.atlassian.jira.user.util.UserUtilImpl.getUsers() is applicable for argument types: () values: [] Possible solutions: getClass(), every()

groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.user.util.UserUtilImpl.getUsers() is applicable for argument types: () values: [] Possible solutions: getClass(), every() at Script8.run(Script8.groovy:13)
Graham Twine
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 13, 2023

Line 13 in the example you have given is not the result of this error :(

 

Line 13 is def CurrentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

 

In the error you have posted above at Script8.run(Script8.groovy:13)

Suggest an answer

Log in or Sign up to answer