I want to automate the population of Epic link from the value selected during the creation of the issue.
Can someone help with the concept of how to achieve this ? Thanks
Since, Epic link denotes the epic, thus it seems you intend to link the story/task to an epic via the epic link field based on a certain custom field value during the post-function of the create transition. I hope I have understood you right.
You can't do this out of the box, but if you have a plugin like Script runner, then it's easily doable.
PLease see here how to set epic link
How to check custom field value using groovy
@Tarun Sapra Hello. Yes you got that absolutely right, . Also, I do have Scriptrunner available. Any help on how this could be accomplished using Scriptrunner ? Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Aisha M
Put the post-function in the very end of the list of post-functions available and go through the links which I shared as they have all relevant code.
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.
Sure @Aisha M
If it works for you then please accept/upvote the answer so that others are helped as well.
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra Hi Tarun, I have added the post function and understood that the links from the scripts could be used for my requirement. But, how do I relate the two scripts, that is, if custom field value is abc, set epic to ABC ? Can you please give in your thoughts. Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Aisha M
You don't need two scripts, in a single script you can fetch the custom field value as described in the links which I have shared and then if the value meets your condition then you can set epic link.
Psuedocode
If(yourCustomField value == what you want) {
then
epicLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(epicLink), epicIssue),new DefaultIssueChangeHolder())
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra Thank you Tarun. Is the below script meaningful,
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def epicIssue = issueManager.getIssueObject("ATOTTS4-107") // Epic issue key here
def epicLink = customFieldManager.getCustomFieldObjectByName("Epic Link")
epicLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(epicLink), epicIssue),new DefaultIssueChangeHolder())
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10259");
def value = (String)issue.getCustomFieldValue(customField);
if(CustomFieldValue==initial) {
epicLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(ATOTTS4-107), epicIssue),new DefaultIssueChangeHolder())
}
Sorry for the trouble , really appreciate your help :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Aisha M
Yes, this script is meaningful, quick query is your customfield "customfield_10259" of type String? i.e. is it a text field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra Yes, its a text field. While I added this script, I get mini pop ups with this error:
The variable 'initial' is undeclared
The value 'ATOTTS4-107' is undeclared
Actually, initial is one of the field value and ATOTTS4 is the epic key
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The if statement should be
if(value == "initial")
instead of if(CustomFieldValue==initial)
And
instead of
epicLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(ATOTTS4-107), epicIssue),new DefaultIssueChangeHolder())
you should write
epicLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue("ATOTTS4-107"), epicIssue),new DefaultIssueChangeHolder())
Also add an import for Component Accessor at the beginning.
import com.atlassian.jira.component.ComponentAccessor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra The first statement is good now :)
But, getting the below error popup for the second statement,
com.atlassian.jira.issue.MutableIssue#getCustomFieldValue
(java.lang.string). Please check if the declared type is right & if the method exists
Also, added the import for Component Accessor :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If the custom field is of type string then it should work fine as you are type casting it to string, thus can you try executing the script
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra Hi Tarun :) The field is a drop down. It did not work. Dunno why.
Also, I added this as the last step of post function at the create issue transition. I hope that's correct.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, Could you please paste the complete code again in code macro and mention the type of each custom field being used in the code
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Custom Field Type - Drop down field
Field Value - initial
Epic Name - ATOTTS4-107
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def epicIssue = issueManager.getIssueObject("ATOTTS4-107") // Epic issue key here
def epicLink = customFieldManager.getCustomFieldObjectByName("Epic Link")
epicLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(epicLink), epicIssue),new DefaultIssueChangeHolder())
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10259");
def value = (String)issue.getCustomFieldValue(customField);
if(value == "initial") {
epicLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue("ATOTTS4-107"), epicIssue),new DefaultIssueChangeHolder())
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Aisha M
Please try this code
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def epicIssue = issueManager.getIssueObject("ATOTTS4-107") // Epic issue key here
def epicLink = customFieldManager.getCustomFieldObjectByName("Epic Link")
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10259");
def value = (String)issue.getCustomFieldValue(customField);
if(value == "initial") {
epicLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(epicLink), epicIssue), new DefaultIssueChangeHolder());
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra The script has zero errors :) Thank you. But, the story is not updating with the Epic link when I select the field value. Dunno whats the problem here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra Below is the log report for the script failing.
2018-06-21 06:48:22,687 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-06-21 06:48:22,687 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ATOTTS4-111, actionId: 1, file: <inline script> java.lang.NullPointerException at com.atlassian.jira.issue.link.DefaultIssueLinkManager.getIssueLink(DefaultIssueLinkManager.java:381) at com.atlassian.jira.issue.link.DefaultIssueLinkManager.createIssueLink(DefaultIssueLinkManager.java:89) at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26) at com.sun.proxy.$Proxy427.createIssueLink(Unknown Source) at com.atlassian.plugin.osgi.bridge.external.HostComponentFactoryBean$DynamicServiceInvocationHandler.invoke(HostComponentFactoryBean.java:136) at com.sun.proxy.$Proxy427.createIssueLink(Unknown Source) at com.atlassian.greenhopper.manager.issuelink.EpicLinkManagerImpl.createLink(EpicLinkManagerImpl.java:322) at com.atlassian.greenhopper.manager.issuelink.EpicLinkManagerImpl.updateLinksForIssues(EpicLinkManagerImpl.java:238) at com.atlassian.greenhopper.manager.issuelink.EpicLinkManagerImpl.associateIssuesWithEpic(EpicLinkManagerImpl.java:179) at com.atlassian.greenhopper.service.issuelink.EpicServiceImpl.addIssuesToEpic(EpicServiceImpl.java:103) at com.atlassian.greenhopper.customfield.epiclink.EpicLinkCFType.associateIssueWithEpic(EpicLinkCFType.java:686) at com.atlassian.greenhopper.customfield.epiclink.EpicLinkCFType.createValue(EpicLinkCFType.java:202) at com.atlassian.greenhopper.customfield.epiclink.EpicLinkCFType.createValue(EpicLinkCFType.java:44) at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:693) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:410) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396) at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source) at Script89.run(Script89.groovy:14)
Issue: ATOTTS4-111
{ "full.module.key": "com.onresolve.jira.groovy.groovyrunnerrungroovy-function (java.lang.String)", "canned-script": "com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction (java.lang.String)", "class.name": "com.onresolve.jira.groovy.GroovyFunctionPlugin (java.lang.String)", "issue": "ATOTTS4-111 (com.atlassian.jira.issue.IssueImpl)", "passesCondition": "true (java.lang.Boolean)", "transientVars": { "entry": "com.opensymphony.workflow.spi.SimpleWorkflowEntry@18d1ff0a", "issue": "ATOTTS4-111 (com.atlassian.jira.issue.IssueImpl)", "configuration": "com.opensymphony.workflow.config.DefaultConfiguration@366e2859", "context": "com.opensymphony.workflow.basic.BasicWorkflowContext@527acb27", "createdStep": "SimpleStep@2[owner=, actionId=0, status=open] (com.opensymphony.workflow.spi.SimpleStep)", "originalissueobject": "null (org.codehaus.groovy.runtime.NullObject)", "actionId": "1 (java.lang.Integer)", "issueProperties": "{} (com.google.common.collect.EmptyImmutableBiMap)", "currentSteps": "[SimpleStep@2[owner=, actionId=0, status=open]] (java.util.ArrayList)", "pkey": "ATOTTS4 (java.lang.String)", "store": "com.opensymphony.workflow.spi.ofbiz.OfbizWorkflowStore@57d2f926", "descriptor": "com.atlassian.jira.workflow.ImmutableWorkflowDescriptor@1331c049" }, "log": "org.apache.log4j.Logger@bd5b3c" }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
instead of last function of create transition can you add this post-function in the end at some other transition i.e. may be start progress or something but not create transition and share the result.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra I don't have any other transition that would make sense. Its more like create - lots of status - Ready to accept - Done
Don't know where else to add this, anyway will give it a shot :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tarun Sapra It did not work Tarun. Any other possibility of achieving this instead of using workflow post functions. Thank you :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.