Assigning assignee automatically using post function

Ilakiya Srinivasan September 2, 2020

Hi,

I have a request type Training, where I want the reporter who creates the ticket(say Lead) to assign the assignee(say New joiner to the team) while creating a ticket in Service Desk. So, I'm using a custom field 'Trainee' in the service desk form and using the post function copy the field value from Trainee to 'Assignee' and then remove the field 'Trainee' from the ticket by setting the value to None. It didn't work. 

Then I tried with the Script runner Post function.

Both the custom fields are 'Single User Picker'. I used the below script. If this is not correct, please help me with correcting where I'm going wrong.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

def cField = customFieldManager.getCustomFieldObject("Trainee")
ApplicationUser user = issue.getCustomFieldValue(cField) as ApplicationUser
UserManager userManager =   ComponentAccessor.getUserManager();
issue.setAssignee((user))

 

2 answers

1 accepted

1 vote
Answer accepted
Ilakiya Srinivasan September 7, 2020

I got this sorted out. 

JIRA doesn't let you change system fields (such as the Assignee field) after the "Creates the issue originally" post-function.

So you should either move the post-function for setting assignee to before the "Creates the issue originally" post-function, or if you can't, your only option is to use the "Transition Issue" post-function to trigger a hidden auto-transition that will update the assignee field.

I was able to move my Post function to copy the field value from Trainee to Assignee and it worked..

0 votes
Rob Horan
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.
September 2, 2020

Does this need to be done with Scriptrunner?  do you have any other plugins, like JSU?

Ilakiya Srinivasan September 7, 2020

Yes, I do have JSU.. What do you suggest...??

Ilakiya Srinivasan September 7, 2020

Hey @Rob Horan , Thanks for your support, I have sorted out where was going wrong.

Rob Horan
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.
September 7, 2020

You're welcome - just curious, what was wrong?

Ilakiya Srinivasan September 11, 2020

I read somewhere in an Atlassian document that JIRA doesn't let you change system fields (such as the Assignee field) after the "Creates the issue originally" post-function.

So you should either move the post-function for setting assignee to before the "Creates the issue originally" post-function, or if you can't, your only option is to use the "Transition Issue" post-function to trigger a hidden auto-transition that will update the assignee field.

I was able to move my Post function to copy the field value from Trainee to Assignee and it worked..

 

Like # people like this
Rob Horan
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.
September 11, 2020

Hmmmm, that's interesting, because I am 99% sure that I've made a ton of post functions in which assignee updates happened after the create issue originally post function happened, but now I need to look :)

Ilakiya Srinivasan September 13, 2020

@Rob Horan I was also wondering the same until I tried...  Found the link where i read it... https://community.atlassian.com/t5/Answers-Developer-Questions/Post-Function-Order-Trying-to-Set-Assignee-Based-on-Field/qaq-p/512759

Check out the answer given by David.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events