Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot access the current issue or fired event from a script in a post function

NikosGr February 2, 2020

Hello, 

I'm trying to write a script in order to set a custom field. I've put in a post function under create transition. Here is the script:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.util.UserManager 
import com.atlassian.jira.event.type.EventDispatchOption

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def multiGroupCf = customFieldManager.getCustomFieldObjectByName("Demo-Π.Σ.Κ.Ε. Assignable Groups") //multigroup picker custom field

def group1 = groupManager.getGroup("EYKE Group") //jira group
def group2 = groupManager.getGroup("Group_Epilogi_Proistamenon") //jira group
def group3 = groupManager.getGroup("ISO - Security Officers") //jira group

def groupList = [group1, group2, group3]

issue.setCustomFieldValue(multiGroupCf, groupList)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

The problem is that when I create a new issue I receive the following error:

We can't create this issue for you right now, it could be due to unsupported content you've entered into one or more of the issue fields. If this situation persists, contact your administrator as they'll be able to access more specific information in the log file.

 

It seems like I can't access the current issue.

Do have any idea about how to solve the problem?

 

Thanks

4 answers

0 votes
NikosGr February 7, 2020

Does anybody have any idea about the issue?

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2020

Two things, although I'm not sure it's either of them:

In a post-function, you do not need to use updateIssue - you're already in the middle of creating.  So I would try removing the last line and moving the function up before "create issue initially"

I'm not sure the custom field accepts an array as a value, I think it might need a collection

NikosGr February 5, 2020

I tried it but no luck. By the way, the custom field accepts an array as a value. I've checked it.

0 votes
Leonard Chew
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 3, 2020

Are you using a Scriptrunner postfunction?

Check the position of your postfunction.
It needs to be AFTER the System Postfunction "Creates the issue originally".

And preferrably before the reindexing Postfunction, so that the new values will be indexed along.

NikosGr February 4, 2020

It is placed exactly where you said but no luck... 

NikosGr February 4, 2020

I'm not using Scriptrunner but the Coderunner, but, I'm not sure if scripts in post function run through Scriptrunner or Coderunner.

0 votes
NikosGr February 2, 2020

The same happens is if I use the variable event instead of issue.

Suggest an answer

Log in or Sign up to answer