Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

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 functionsfunctions 

Info

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.



Example Scenario

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

...

Code Block
languagegroovy
linenumberstrue
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"]
}


Tip

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

Code Block
languagegroovy
def lookupValue;
//Load the team entity property from the issue if user has permission to read the issue
def issueProperty = issuePropertyService.getProperty(user, issue.getId(), "team").getEntityProperty().getOrNull()
if (issueProperty)
{
    //extract the value out
    lookupValue = issueProperty.getValue(); 
}
else
{
   //set it to an empty string if there is no team entity property stored within the specified issue
   lookupValue = "";
}