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

Change the assignee field from a custom field (user picker) Edited

Karim Belhadj Apr 01, 2019

hello team 

I would like to filfil the system field assignee from a custom field , type of custom field = User picker . so i find trhis code but it work here , but when i put it in a post function , the assignee does not change  .

 

Image 2.png

 

i need your help.

 

Regards

3 answers

1 vote
Antoine Berry Apr 01, 2019

Hi,

This snippet should work fine : 

def customFieldManager = ComponentAccessor.getCustomFieldManager()

//Jira User picker ID
int userPickerId = 10013
def cfUserPicker = customFieldManager.getCustomFieldObject(userPickerId)
def cfUserPickerValue = issue.getCustomFieldValue(cfUserPicker)

issue.setAssignee(cfUserPickerValue)

If it does not, add some logs to check where it is failing.

Antoine 

Karim Belhadj Apr 01, 2019

hi @Antoine Berry .

Thank you , yes there are always the same problem , i make some log but it return coorect result , but when i go to the issue there are always the same user assignee , it does not change .

Image 6.png

 

 

 

i can not understand what's the problem , also there are a warn appear , in the picture .

 

 

Regards

Antoine Berry Apr 01, 2019

Don't worry about the WARN, it shows because we did not specify the type of cfUserPickerValue. But it is groovy so it is not a problem, as you can see it executes correctly. 

Did the assignee change ?

Karim Belhadj Apr 01, 2019

@Antoine Berry  no the assignee do not change , it still the same

Antoine Berry Apr 01, 2019

Weird, this is working fine with me.

Can you add 

def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
issue.store()
issueIndexingService.reIndex(issue)

at the end ? See if that helped and provide a screenshot again ?

Thanks

Karim Belhadj Apr 01, 2019

there are another problem appear 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
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.jira.user.ApplicationUser
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
import com.atlassian.jira.user.util.UserManager

def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("AB-1");
//Jira User picker ID
int userPickerId = 10013
def cfUserPicker = customFieldManager.getCustomFieldObject(userPickerId)
log.warn("customfield " + cfUserPicker )
def cfUserPickerValue = issue.getCustomFieldValue(cfUserPicker)
log.warn("current assignee == " + issue.assignee )


issue.setAssignee(cfUserPickerValue)
log.warn(" new assigneee = " + cfUserPickerValue )

def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
issue.store()
issueIndexingService.reIndex(issue)

 

 

Image 7.png

 

regards

Antoine Berry Apr 01, 2019

Ah, no big deal, just an import missing. Try

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
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.jira.user.ApplicationUser
import com.atlassian.jira.issue.index.IssueIndexingService

def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
import com.atlassian.jira.user.util.UserManager

def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("AB-1");
//Jira User picker ID
int userPickerId = 10013
def cfUserPicker = customFieldManager.getCustomFieldObject(userPickerId)
log.warn("customfield " + cfUserPicker )
def cfUserPickerValue = issue.getCustomFieldValue(cfUserPicker)
log.warn("current assignee == " + issue.assignee )


issue.setAssignee(cfUserPickerValue)


def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
issue.store()
issueIndexingService.reIndex(issue)
log.warn(" new assigneee = " + issue.assignee )

I added the value of the assignee at the end so we can see if it updated successfully.

Karim Belhadj Apr 01, 2019

now it works fine thank you

0 votes
Alexander Pappert Apr 01, 2019

You want to fill Assignee from a custom user picker field, when a specific Transition/status is reached (i.e. Task is opened, set to V&V, ...)?

there are several addons on Marketplace which help you to do this.

a free one is for example https://marketplace.atlassian.com/apps/1211836/automation-lite-for-jira?hosting=server&tab=overview

https://docs.automationforjira.com/getting-started/actions.html#add-service-desk-customer

Karim Belhadj Apr 01, 2019

@Alexander Pappert  i need this with a sample code script runner , i do not ask for addon , thank you.

0 votes
Alexander Apr 17, 2019

Hi @Karim Belhadj 
Try this:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.user.ApplicationUser;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

def issue = ComponentAccessor.issueManager.getIssueByCurrentKey('AB-1'); 

def cField = customFieldManager.getCustomFieldObjectByName("Your cf name"); // You can use ID
ApplicationUser user = issue.getCustomFieldValue(cField) as ApplicationUser;
issue.setAssignee(user);
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);

Give me an answer about the result!

Good luck!

 

Regards

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

1,142 views 2 13
Read article

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