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

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

This widget could not be displayed.

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)

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]

This widget could not be displayed.

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

This widget could not be displayed.

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.

This widget could not be displayed.

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.

This widget could not be displayed.

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).

This widget could not be displayed.

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!

This widget could not be displayed.

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.

This widget could not be displayed.

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

531 views 3 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you