Can't set epic link in a script

Hi there,

I have a manager who wants to have a transition on epics for the purpose of creating a set of stories.

I can create his list of issues and set various custom fields for him in a pastfunction, but nothing I do sets the Epic link.

I have tried by issue ID and key, and also tried using a text custom field I created to hold the issue key value.

Logger.getLogger("com.onresolve.scriptrunner").setLevel(Level.DEBUG
Issue issue  = issue def id=sourceIssue.key
// Get the Epic Link field
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link')
// Create the issue
issue.summary = 'Create tenant for ' + sourceIssue.key
checkAttachment = {attachment -> false}
issue.assignee = null
issue.setCustomFieldValue(epicLink,id)

 

I also can't seem to import any greenhopper methods nor call the epicLinkManagerImpl as a bean.

Is there any way to do this in JIRA 7.1 with the latest ScriptRunner, or would it help in any way to upgrade Jira? Maybe I could sacrifice a goat or something?

Thanks in advance for all your help!

3 answers

1 accepted

1 vote
Accepted answer

If I remember correctly, you should store issue object for epic link field. Like:

issue.setCustomFieldValue(epicLink,sourceIssue)

Why doesn't this work for me?

(is the issue type wrong?)

I get

2017-03-10 11:31:56,640 WARN [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.DocumentIssueImpl.setCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl, null) values: [PMOA-40, null] Possible solutions: getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField) at Script1636$_run_closure1.doCall(Script1636.groovy:42) at Script1636.run(Script1636.groovy:28)

Yup, just test checkLink = {link -> false} in the subtasks, and that fixed it up just fine.

Thanks again for the save smile

And clear the epic link. Thus:

checkLink = {link -> false}
def epic = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}
issue.setCustomFieldValue(epic, null)
Strange that you need both.. JIRA keeps suprising me every day..

Help!

Why am I getting (with the code above)

 

Error

No signature of method: com.atlassian.jira.issue.DocumentIssueImpl.setCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.ImmutableCustomField, null) values: [Epic Link, null] Possible solutions: getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField)

which version of JIRA do you have?

We are on 7.2.7 Server, with ScriptRunner latest

You need the MutableIssue interface. If you use this method from a ScriptRunner workflow function, the issue is already of type MutableIssue. If you write your own groovy script, you have to use com.atlassian.jira.issue.MutableIssue.

I think this all depends on exactly where you run the statements.

I am using them as a condition with the built-in post function to create a sub-task.Works fine.

It looks like other folks in the thread may be trying these lines in the console or perhaps a custom script, so of course this will behave differently, as the imports and variable declarations in the built-in script will not be present in the console.

Holy cow IT WORKS!!!!

Alexey, you are awesome smile

The only bad thing that happened is that on the Training issue type, which creates a set of subtasks on creation, it copied the Epic link to those.

Do you think I could get rid of that with checkLink = {link -> false}, or is that fallout from that recent bug I think I recall seeing?

Epic Link is different from usual issue links, you should set value of this field to null in cloned issue.

More here https://answers.atlassian.com/questions/40003636

Ah, I see what you mean. I bet this only seemed to work because of the subtask issue type.

For safety, I've also added:

//Kill the little b*tard 
def epic = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'} 
issue.setCustomFieldValue(epic, null)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,378 views 0 8
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