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

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 Community Leader 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 

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 Community Leader 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 ?

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

Antoine Berry Community Leader 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

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 Community Leader 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.

now it works fine thank you

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

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

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
Community showcase
Posted in Jira

Calling all Jira Cloud users! Give us feedback on our exploration of a new navigation.

Hi everyone! My name’s Matt and I’m a product manager at Atlassian. I work in the navigation & findability space for all our Jira Cloud products. We’ve been working on trying to improve the exp...

899 views 14 12
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