This guide explains how you can extract the stored properties from an issue using ScriptRunner. With that, you can use the information to perform other script runner functions
Entity properties are hidden and does not require a separate custom field to store the data. The values can be queried from REST API or JQL. |
Let's say you have five teams each with one leader and 5 agents. As an administrator, you want to create a Round Robin Assignment Rule to equally distribute the tickets to the agent in the team. One possible way is to use Lookup Manger and ScriptRunner
1. Create a Lookup Table
The value in the Team column must be a valid JSON Object. Eg. {"name": "Team A", "agents": {"agent_1":"Enrico", "agent_2" : "Maiya", "agent_3" : "Tyson", "agent_4" : "Leyla", "agent_5" : "Tate"}} |
Check out how to create a lookup table
2. Create LookupManager: Add/Update Issue Property Function
Check out how to create workflow post function to update issue property
3. Create Script Post-Function(ScriptRunner)
import groovy.json.JsonSlurper import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.bc.issue.properties.IssuePropertyService def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def issuePropertyService = ComponentAccessor.getComponentOfType(IssuePropertyService.class) def parser = new JsonSlurper() // The entity key from workflow function def entityKey = 'team' // The entity name from the lookup table def teamEntityName = 'name' def agentsEntityName = 'agents' def issueProperties = issuePropertyService.getProperties(user, issue.getId()) def team = "" def agents = "" def assignee = "" issueProperties.each { property -> if (property.getKey().equals(entityKey)) { //Convert string to json, and obtain the value def json = parser.parseText( property.getValue()) team = json[teamEntityName] agents = json[agentsEntityName] assignee = roundRobinAssignment(agents); } } def roundRobinAssignment(agents) { //Write your own implementation here return agents["agent_1"] } |
EntityPropertyService allows reading a specific property from the issue. If the lookup value is just a plain text string, you can use the following code example below to extract out the value
|