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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am expecting a script which shows total no of licenses used in Jira, Confluence , bitbucket, JSD and available licenses in all the applications
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
May I know which file we have to add in home directory? I am getting the above error when I run code in console
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Can you give us the full error message you got please
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No signature of method: com.atlassian.jira.user.util.UserUtilImpl.getUsers() is applicable for argument types: () values: [] Possible solutions: getClass(), every()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
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.