3 min read
Unlimited JSM License? How to find the real agents at JSM for the right Cloud or DC license
Deniz
:
Jun 19, 2023 10:53:54 AM
Managing user licenses and determining the number of active agents in Jira Service Management (JSM) is crucial when organizations transition to the Atlassian Cloud or Data Center platforms. As subscription costs are based on the number of users, accurately assessing the user count becomes a significant challenge. To address this issue, we have developed a Groovy script that leverages Adaptavist Scriptrunner for Jira to determine the number of active JSM agents in your organization.
Let's explore how this script works and how it can simplify user management in Jira Service Management.
The Code
The given Groovy script leverages Jira's official Java API to achieve the same outcome as an SQL statement. The code executes the following actions:
- Retrieves a collection of all active users in the 'jira-servicedesk-users' group, which typically consists of JSM agents.
- Fetches a list of JSM projects presented in your Jira instance.
- Verifies whether each user has edited at least one ticket within a JSM project.
- Compiles a roster of user names that satisfy the given criteria.
The Groovy script below, developed to be used with Adaptavist Scriptrunner for Jira, uses Jira's official Java API to answer this question. Additionally, it gives the same function as SQL statement.
Here are your Codes:
-
SQL Code
SELECT DISTINCT u.lower_user_name
FROM cwd_user u
JOIN cwd_membership m ON u.id = m.child_user_id
JOIN cwd_group g ON m.parent_id = g.id
JOIN app_user au ON u.lower_user_name = au.user_key
JOIN changegroup cg ON au.user_key = cg.author
JOIN jiraissue ji ON cg.issueid = ji.id
JOIN project p ON ji.project = p.id
JOIN nodeassociation na ON p.id = na.source_node_id
WHERE u.active = 'T'
AND g.lower_group_name = 'jira-servicedesk-users'
AND na.sink_node_entity = 'ProjectType'
AND na.sink_node_id = (SELECT id FROM projecttype WHERE "key"='service_desk
-
Groovy Code
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
def groupManager = ComponentAccessor.getGroupManager()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def projectManager = ComponentAccessor.getProjectManager()
// Holen Sie sich alle aktiven Benutzer in der Gruppe 'jira-servicedesk-users'
def users = ComponentAccessor.getUserManager().getUsersInGroup('jira-servicedesk-users').findAll { it.isActive() }
// Holen Sie sich alle JSM-Projekte
def jsmProjects = projectManager.getProjectObjects().findAll { it.projectTypeKey.key == 'service_desk' }
// Ergebnis
def result = []
users.each { user ->
def userHasEditedJSMIssue = jsmProjects.any { project ->
def issuesInProject = ComponentAccessor.getIssueManager().getIssueObjects(ComponentAccessor.getIssueManager().getIssueIdsForProject(project.id))
issuesInProject.any { issue ->
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "*")
changeItems.any { ChangeItemBean changeItemBean ->
changeItemBean.getUserKey() == user.key
}
}
}
if (userHasEditedJSMIssue) {
result << user.name
}
}
return result
-
For tickets created within the last 3 months
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
def groupManager = ComponentAccessor.getGroupManager()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def projectManager = ComponentAccessor.getProjectManager()
// Holen Sie sich alle aktiven Benutzer in der Gruppe 'jira-servicedesk-users'
def users = ComponentAccessor.getUserManager().getUsersInGroup('jira-servicedesk-users').findAll { it.isActive() }
// Holen Sie sich alle JSM-Projekte
def jsmProjects = projectManager.getProjectObjects().findAll { it.projectTypeKey.key == 'service_desk' }
// Zeitpunkt vor 3 Monaten
def threeMonthsAgo = new Date() - 3.months
// Ergebnis
def result = []
users.each { user ->
def userHasEditedJSMIssue = jsmProjects.any { project ->
def issuesInProject = ComponentAccessor.getIssueManager().getIssueObjects(ComponentAccessor.getIssueManager().getIssueIdsForProject(project.id))
issuesInProject.any { issue ->
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "*")
changeItems.any { ChangeItemBean changeItemBean ->
changeItemBean.getUserKey() == user.key && issue.getCreated().after(threeMonthsAgo)
}
}
}
if (userHasEditedJSMIssue) {
result << user.name
}
}
return result
Important Considerations
While the script is incredibly useful, it's important to keep the following points in mind:
- High System Load: Running the script through all projects and tickets can potentially strain the system. We strongly recommend testing it in a non-production environment before deploying it in a live environment.
- Customization: Depending on your Jira instance's requirements and size, you may need to customize the script. Consider it as a starting point that can be modified to suit your specific needs.
How will this help me?
Determining the number of active JSM agents is a critical task when managing user licenses in Jira Service Management. Our provided Groovy script offers a practical solution to this challenge, simplifying user management and facilitating cost calculations for cloud or data center subscriptions. However, exercise caution when running the script and always test it in a safe environment before deploying it in your production setup.
If you have any questions or require further customizations, please don't hesitate to reach out to us. We're here to help you make the most of Jira Service Management and optimize your user management processes.
More about Jira Service Management and our licenses
Jira Service Management trainings
Atlassian Enterprise License Agreement (ELA)
The Future of ITSM with Atlassian