Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic Routing of Jira Issues to a set of User Roles

Akbar N October 24, 2018

Hi, 

We are trying to achieve the following in our Jira Ent Cloud and allowed to use any plugins or custom code. Any suggestion will be highly appreciable. 

  • As per our use case, we want every issues created to be routed to set of different  roles based on the values selected in the ticket
  • Ex-1: An issue with Argentina selected as values for a custom select field needs to be assigned to Argentina approver role automatically followed by set of another approvals without any manual intervention.
  • Ex-2: An issues with Spain selected as a value for a custom select field needs to be assigned to Spain approver role automatically followed by next set of approvals.

 Thanks

2 answers

1 vote
Ismael Jimoh
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.
October 24, 2018

You would need to script this.

My suggestion is that you add the script to your post function of your create transition and the script does the following:

  • Check the value of the field.
  • Set assignee field to the corresponding approver for the region.

I will recommend scriptrunner for this job(a paid add-on but they have a very active community).

You can look up get value of field samples for the add-on and you can look up how to assign an issue to a user.

I hope this helps.

Regards.

Akbar N October 24, 2018

Thanks for sharing the idea and possible approach. As we are on the On-demand cloud enterprise edition, there are some limitation on installing plugins just for a requirement to a project in Jira as it impact the entire enterprise edition used by 500+ projects. 

Is there any other possible options without it? 

 

Thanks again for your input. 

Ismael Jimoh
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.
October 26, 2018

It would be near impossible without a custom script and add-on. JIRA has no built in way to set the value of a field based on another field.

With the only other solution coming to mind being splitting the projects based on Geo location/team that would work on it.

Akbar N October 26, 2018

Thanks for the details again. Got the confirmation that we have ScriptRunner installed in our Ent edition of Jira. Could you help on how to get started with ScriptRunners. It seems there were very less tutorials online and to the detailed.

http://scriptrunner-docs.connect.adaptavist.com/jiracloud/quickstart.html

Could you share any video / tutorial links which talks about creating custom fields, dynamic fields etc ?

Ismael Jimoh
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.
October 29, 2018

Hi Akbar,

Sorry for the late reply.

You can learn about Scriptrunner for Cloud here. Also as Scriptrunner is based on the REST API for Cloud, you will want to familiarize yourself with this.

  • Could you share any video / tutorial links which talks about creating custom fields, dynamic fields etc ?
  • Note though that I will not recommend creating a script using scriptrunner this is a bad practice in general.

Your original description points to you wanting to update a field based on another field.

In such a case, you would need to:

  • Get the value of field A.
  • Validate using either CASE or If/Else conditions
  • Set the Assignee for to the group/user you want.

Hope the above helps with getting you started.

Ismael Jimoh
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.
October 29, 2018
/**
* Author: Ismael Olusola JIMOH
* Product: Atlassian JIRA Cloud
* Description: Set the value of the Territory Manager Field based on What is selected as the Territory field
*/

package com.adaptavist.sr.cloud.samples.events

def projectKey = "ABCD"

if (issue == null || issue.fields.project.key != projectKey) {
logger.info("Wrong Project ${issue.fields.project.key}")
return
}

def issueKey = issue.key
def territory = 'customfield_10030'
def territoryManager = 'customfield_10031'
def territoryResult
def managerResult

def result = get("/rest/api/2/issue/${issueKey}?fields=${territory}")
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200) {
territoryResult = result.body.fields[territory].value.toString()
//return territoryResult
if(territoryResult=="[UK]"){
//Replace the value in the name put parameter with the name of the current territory manager
def setManager = put("/rest/api/2/issue/${issueKey}?fields=${territoryManager}")
.header('Content-Type', 'application/json')
.body([
fields:[
customfield_10031:[
name:'''<username goes here>'''
]
]
])
.asObject(Map)
return setManager
}else if(territoryResult=="[US]"){
//Replace the value in the name put parameter with the name of the current territory manager
def setManager = put("/rest/api/2/issue/${issueKey}?fields=${territoryManager}")
.header('Content-Type', 'application/json')
.body([
fields:[
customfield_10031:[
name:'''<username goes here>'''
]
]
])
.asObject(Map)
}else if(territoryResult=="[Germany]"){
//Replace the value in the name put parameter with the name of the current territory manager
def setManager = put("/rest/api/2/issue/${issueKey}?fields=${territoryManager}")
.header('Content-Type', 'application/json')
.body([
fields:[
customfield_10031:[
name:'''<username goes here>'''
]
]
])
.asObject(Map)
}else{
return "Global or more than one territory was selected, select only one Territory."
}
} else {
return "Error retrieving issue ${result}"
}

This is a sample I wrote a while back where I am checking the value of a field Called Territory and Setting the Territory Manager.

So the concept of what you will be achieving is similar to the above.

Akbar N October 29, 2018

Thanks a ton for this script and i will try to see how i can fit this in my requirement. 

I will definitely will come back for other questions and thank for taking time to address. 

Akbar N October 29, 2018

Hi Ismael, One other quick question. I was getting an error when trying the following code. The error is on using the setHidden and setRequired. I was trying to show / hide a text field based on the selection of value select field. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.resolution.Resolution

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()


def complianceReviewNotRequiredField = customFieldManager.getCustomFieldObjectByName("Compliance Review not required")
def complianceReviewField = customFieldManager.getCustomFieldObjectByName("Compliance Requirement")


def selectedOption = complianceReviewField.getValue(issue).toString()
def isOtherSelected = selectedOption == "Approval Not Needed"

if(selectedOption == "Approval Not Needed"){
complianceReviewNotRequiredField.setHidden(false)
complianceReviewNotRequiredField.setRequired(true)
}

Ismael Jimoh
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.
October 31, 2018

Hi Akbar,

I am unfamiliar with these methods. Also our code looks like it was written for Server rather than Cloud because with Cloud most calls are based on the Cloud Rest API.

Secondly, you are getting a custom field object rather than the customfield itself.

Replace:

def complianceReviewNotRequiredField = customFieldManager.getCustomFieldObjectByName("Compliance Review not required")
def complianceReviewField = customFieldManager.getCustomFieldObjectByName("Compliance Requirement")

With:

def complianceReviewNotRequiredField = getFieldByName("Compliance Review not required")
def complianceReviewField = getFieldByName("Compliance Requirement")

 

This should fix the issue you are having with the setHidden but I still do not know are you working with Cloud as you stated earlier or you are running JIRA on your own server?

Ismael Jimoh
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.
October 31, 2018

This is best explained here: https://community.atlassian.com/t5/Jira-questions/error-on-setHidden/qaq-p/771745 but note my question on which JIRA you are using.

Akbar N October 31, 2018

Hi Ismael, Sorry for the confusion and just got a confirmation from our systems that we are running jira Server instance not the Cloud. I know it's my mistake for not informing. 

We are on the server version 7.6.4. I know this will be a repeated work but could you pls clarify me on the above code you have provided for handling approvals will work on server version?

Thanks in Adavance. 

Ismael Jimoh
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.
October 31, 2018

As you are using Server, then the original script I provided you will not work.

The section I corrected for you in the code you shared should. Do test it and if you have any questions, let me know and specify what the error is.

Regards.

Akbar N October 31, 2018

No Ismael I'm still getting error. Not sure what is happening.

Akbar N November 1, 2018

Finally i made it working. Thanks for your suggestions. 

def extCommSelectCf = getFieldById("customfield_18903") //get the field ID for Linked to externally committed release date (e.g. marketing)?
def extCommmDateCf = getFieldById("customfield_18902") //get the ID for Externally Committed Launch Date
extCommmDateCf.setHidden(true);

if (extCommSelectCf.getValue() == "Yes"){
extCommmDateCf.setHidden(false);
extCommmDateCf.setRequired(true);

Like Ismael Jimoh likes this
Akbar N November 1, 2018

Hi Ismael, would it be possible to share the modified jira server version of your territory manager code? or let me know which areas needs change. 

Ismael Jimoh
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.
November 1, 2018

Unfortunately, I do not have the script in server version.

 

also though the logic is the same all the get and put sections must be replaced which means a rewrite of almost the whole script 

0 votes
Joe Pitt
Community Champion
October 24, 2018

You're going to have to do some serious scripting. I don't believe there is a plugin that handles this. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events