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.
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]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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_
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.