Can't set epic link in a script

April December 15, 2016

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
Answer accepted
Alexey Belostotskiy December 15, 2016

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

issue.setCustomFieldValue(epicLink,sourceIssue)
craig.harris@fnb.co.za March 9, 2017

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)

1 vote
April December 15, 2016

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

Thanks again for the save smile

M Hoogenboom January 24, 2017

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..
craig.harris@fnb.co.za March 9, 2017

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)

M Hoogenboom March 9, 2017

which version of JIRA do you have?

April March 10, 2017

We are on 7.2.7 Server, with ScriptRunner latest

M Hoogenboom March 12, 2017

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.

Like Fred Kendall likes this
April March 13, 2017

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.

Like Fred Kendall likes this
0 votes
April December 15, 2016

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?

Alexey Belostotskiy December 15, 2016

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

April December 15, 2016

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
TAGS
AUG Leaders

Atlassian Community Events