It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Update/Set/Edit Assignee field - value from custom field

Hi,

I try update assignee field on postfunction. I read several topics, but I have a problem still.

My code:

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.fugue.Option
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User


log.setLevel(Level.DEBUG)
//Grab necessary Components
def cfm = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def userManager = ComponentAccessor.getUserManager()
def issueService = ComponentAccessor.getIssueService()

def RealizujacyCf = cfm.getCustomFieldObject(11701L)
log.info("RealizujacyCf: " + RealizujacyCf)
def RealizujacyValue = issue.getCustomFieldValue(RealizujacyCf)
log.info("RealizujacyValue: " + RealizujacyValue)
def ClassOfField = RealizujacyValue.getClass()
log.info("ClassOfField: " + ClassOfField)
def ArreySize = RealizujacyValue.size()
log.info("ArreySize: " + ArreySize)


def Realizujacy = issue.getCustomFieldValue(RealizujacyCf).get(0).getName()
log.info("Realizujacy: " + Realizujacy)
def cfWlasciciel = cfm.getCustomFieldObject(11100L)


def user = userManager.getUserByName(Realizujacy);
def validateAssignResult = issueService.validateAssign(user, issue.id, issue.reporterId)
log.info("validateAssignResult: " + validateAssignResult)
//issueService.assign(user, validateAssignResult)

log.info("user: " + user)

//issue.store();

This line return the name of user, ex.: anowak(anowak),

def user = userManager.getUserByName(Realizujacy);

Now, I'd like to update assignee filed with value of "user ".

Without this line:

issueService.assign(user, validateAssignResult)

I have this result:

2019-03-26 16:27:39,829 INFO [workflow.ScriptWorkflowFunction]: RealizujacyCf: Realizujący
2019-03-26 16:27:39,830 INFO [workflow.ScriptWorkflowFunction]: RealizujacyValue: [anowak(anowak)]
2019-03-26 16:27:39,830 INFO [workflow.ScriptWorkflowFunction]: ClassOfField: class java.util.ArrayList
2019-03-26 16:27:39,830 INFO [workflow.ScriptWorkflowFunction]: ArreySize: 1
2019-03-26 16:27:39,830 INFO [workflow.ScriptWorkflowFunction]: Realizujacy: anowak
2019-03-26 16:27:39,830 INFO [workflow.ScriptWorkflowFunction]: user: anowak(anowak)
2019-03-26 16:27:39,830 INFO [workflow.ScriptWorkflowFunction]: validateAssignResult: com.atlassian.jira.bc.issue.IssueService$AssignValidationResult@330196c2

But with this line:

issueService.assign(user, validateAssignResult)

I have this result:

2019-03-26 16:32:23,095 INFO [workflow.ScriptWorkflowFunction]: RealizujacyCf: Realizujący
2019-03-26 16:32:23,095 INFO [workflow.ScriptWorkflowFunction]: RealizujacyValue: [anowak(anowak)]
2019-03-26 16:32:23,095 INFO [workflow.ScriptWorkflowFunction]: ClassOfField: class java.util.ArrayList
2019-03-26 16:32:23,096 INFO [workflow.ScriptWorkflowFunction]: ArreySize: 1
2019-03-26 16:32:23,096 INFO [workflow.ScriptWorkflowFunction]: Realizujacy: anowak
2019-03-26 16:32:23,096 INFO [workflow.ScriptWorkflowFunction]: user: anowak(anowak)
2019-03-26 16:32:23,096 INFO [workflow.ScriptWorkflowFunction]: validateAssignResult: com.atlassian.jira.bc.issue.IssueService$AssignValidationResult@1db86722
2019-03-26 16:32:23,098 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-03-26 16:32:23,098 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script>
java.lang.IllegalArgumentException: Issue cannot be null.
 at com.atlassian.jira.issue.fields.layout.field.AbstractFieldLayoutManager.getFieldLayout(AbstractFieldLayoutManager.java:135)
 at com.atlassian.jira.bc.issue.DefaultIssueService.assign(DefaultIssueService.java:557)
 at com.atlassian.jira.bc.issue.IssueService$assign$0.call(Unknown Source)
 at Script462.run(Script462.groovy:49)

Could you help me? :( 

1 answer

1 accepted

1 vote
Answer accepted
Antoine Berry Community Leader Mar 27, 2019

Hi,

You are not using the correct method. I would advise to use : 

issue.setAssignee(user)

Antoine

Thank you very much.

Right code looks like:

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.fugue.Option
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User


log.setLevel(Level.DEBUG)
//Grab necessary Components
def cfm = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def userManager = ComponentAccessor.getUserManager()
def issueService = ComponentAccessor.getIssueService()

def RealizujacyCf = cfm.getCustomFieldObject(11701L)
log.info("RealizujacyCf: " + RealizujacyCf)
def RealizujacyValue = issue.getCustomFieldValue(RealizujacyCf)
log.info("RealizujacyValue: " + RealizujacyValue)
def ClassOfField = RealizujacyValue.getClass()
log.info("ClassOfField: " + ClassOfField)
def ArreySize = RealizujacyValue.size()
log.info("ArreySize: " + ArreySize)


def Realizujacy = issue.getCustomFieldValue(RealizujacyCf).get(0).getName()
log.info("Realizujacy: " + Realizujacy)
def cfWlasciciel = cfm.getCustomFieldObject(11100L)


def user = userManager.getUserByName(Realizujacy);
log.info("user: " + user)
def validateAssignResult = issueService.validateAssign(user, issue.id, issue.reporterId)
log.info("validateAssignResult: " + validateAssignResult)
issue.setAssignee(user)

//issueService.assign(user, validateAssignResult)
//issue.store();

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Portfolio for Jira

Program managers, we need your help! We want to learn about how you plan work for a team of teams

Hi community members, My name is Erika and I’m a product manager at Atlassian. We’re currently investigating how teams are planning work at the program level. We understand that every team in a tea...

145 views 0 5
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you