Jira Behaviours script to set custom field based on custom field of related Epic

Deleted user July 2, 2014

Hi,

I'm trying to write a Jira Behaviours script to automactically set a custom field value ("SVR") of a story based on the SVR of its Epic.

My script is below, but I'm struggling to access the epic issue, and it's properties. can anyone help?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager 
import com.atlassian.jira.issue.fields.CustomField

FormField SVR = getFieldByName("SVR Number");
FormField epicLink = getFieldByName("Epic Link");

Issue epic = issueManager.getIssue(epicLink);

def epicSVR = epic.getFieldByName("SVR Number");

SVR.setFormValue(epicSVR);

thanks,

Mark.

8 answers

1 accepted

6 votes
Answer accepted
Deleted user July 3, 2014

Thanks Jamie - that worked. I've now got the script working (although problably not as elegently as you would have done it).

How do I convert your comment to an answer so you get the points?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager 
import com.atlassian.jira.issue.fields.CustomField

FormField SVR = getFieldByName("SVR Number")
FormField epicLink = getFieldByName("Epic Link")

def epicLinkKey = epicLink.value.replaceAll("key:", "")

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

def epic = componentManager.getIssueManager().getIssueObject(epicLinkKey)

cfSVR = customFieldManager.getCustomFieldObjectByName("SVR Number")

def epicSVR = epic.getCustomFieldValue(cfSVR) 


SVR.setFormValue(epicSVR)

Eunice Mora February 26, 2015

Hi Mark, I'm trying yo use this logic in my script to get the epic record and it's fields' values but I'm getting the error below. I'm running JIRA 6.3.3 and JIRA Agile 6.4.4. What version are you running? It seems not to like the "getIssueObject()". Do you have any ideas? Error: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.managers.DefaultIssueManager.getIssueObject() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl) values: [Epic Link]

Azfar Masut
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.
February 24, 2019

getting errors on this lines, saying classes is invalid. Anyone, help?

 

CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
def epic = componentManager.getIssueManager().getIssueObject(epicLinkKey)
def epicSVR = epic.getCustomFieldValue(cfSVR) 

 

It said, cannot fine matching method com.atlassian.jira.ComponentManager#getCustomFieldManager() eventho ive already imported those classes.

Help? @Adaptavist Supp @Jamie Echlin _ScriptRunner - The Adaptavist Group_ 

0 votes
Deleted user July 3, 2014

Thanks Jamie, seems to work fine where the epic link is empty. I want users to be able to override this default if they want, so works fine.

I wanted to convert your comment to an asnwer so you get the karma points, but couldn't see how. I guess it makes more sense that my working code is flagged though.

Thanks again.

0 votes
JamieA
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.
July 3, 2014

Cool. Looks fine. But don't forget to test where the user doesn't set the epic link etc.

Also please convert your previous comment to an answer and accept it... might help someone.

0 votes
JamieA
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.
July 3, 2014

Great, it looks like a good idea. Final thing that jumps to mind is you might want to test if the Client field is actually empty or not before you set it, it's possible a user may have chosen the client before setting the epic link.

Feel free to "like" my comments, that gives me a karma boost!

0 votes
JamieA
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.
July 2, 2014

def issueKey = epicLink.value.replaceAll("key: ", "")

that should work.

You can use the form values but there's no need, unless the epic link is being set in that form (in which case you must use the form value).

0 votes
Deleted user July 2, 2014

I'm still struggling with this. I don't understand how to use the underlying issue, or epic links - wht can't I just use the form values to get the object?

I'm getting close, but the problem seems to be that get the value I'm getting back from the Epic LInk field is "key: ABC-123" rather than just "ABC-123" so I can't use "getIssueObject"

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager 
import com.atlassian.jira.issue.fields.CustomField

FormField SVR = getFieldByName("SVR Number")
FormField epicLink = getFieldByName("Epic Link")

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

def epic = componentManager.getIssueManager().getIssueObject(epicLink.value)

def epicSVR = epic.getCustomFieldValue("Epic Link")

SVR.setFormValue(epicSVR)

Can anyone help?

thanks.

Mark.

0 votes
JamieA
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.
July 2, 2014

You're going to need to add some debug messages so you can see what you have.

You don't need to look up the epic link from the form, you have the issue (getUnderlyingIssue()) so you can use IssueLinkManager to get the epic link, then then the epics from the epic links.

0 votes
Deleted user July 2, 2014

Thanks Jamie - can you please point me towards some relevant documentation or similar code examples that can help me with this?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events