Forums

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

Is it possible to use the assingment selection in a post function?

Stefan Stadler
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.
January 31, 2024

Hi all,

I am wondering, if it is possible to use the value for auto assignment of an issue in a post function right after it has been created.

Scenario: 

During issue creation, I have the option to either choose an engineer as assignee, select "Automatic" or select "Unassigned".

In case of "Automatic", I would like to have the reporter be set as assignee, while "Unassigned" shall stay unassigned.

The function to populate the assignee if it is empty is running in a post function via Script Runner. However, I did not find a way to check, whether "Automatic" or "Unassigned" has been chosen during creation. 

Is that even possible? Or is there another way to resolve the "Automatic" to assign the reporter based on issue types?

Thanks!

1 answer

1 accepted

1 vote
Answer accepted
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.
January 31, 2024

Welcome to the Atlassian Community!

"no", is the short answer.

Detecting "automatic" is the problem.  That choice is not actually stored anywhere, by the time you get to a post function, Jira has worked out who the assignee should be and populated the field in the working draft of the issue that will eventually be written to the database.  Post-functions have access to that draft, but issue.assignee in there will have a user in it, not "automatic".

But you could fool it a bit.  The "automatic" selection works off a couple of project settings.

  • If there is a component named on the issue, then look at the component settings for the assignee.  The choices there are:
    • Project Lead
    • Component Lead
    • Unassigned
    • Project default
  • If the component says "project default", then use project default as below
  • If there is no component, then use project default.  That is set in the project settings and has the choice of 
    • Project Lead
    • Unassigned

So, my trick here would be to mildly abuse the "project lead".  Set the default assignee to be the project lead, then all the components to project default or project lead.  Then you can code for "if assignee = Bob, the project lead is selected, override it with the reporter".

The problems with this are:

  • If Bob is genuinely selected as the engineer, rather than "automatic", then that's going to get overridden.  You could get around this by setting a project lead to be someone who is unlikely to be assigned issues during creation (even a dummy user), or doesn't mind that this will happen (they can always be assigned back to the issue on edit or reassign).
  • Your project lists are going to name someone who may not really be the actual project lead.  (I don't know of many places that really use project lead to show the business owner of the project, they usually use it for "the person best placed to assign the issue to the right member of the team.  If in doubt, assign it to Bob, Bob will reassign it to the right person")
Stefan Stadler
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 1, 2024

Thanks Nic for that idea. 

I was also thinking about setting a default user. Thinking about this, will the replacing user be notified about the issue creation if the dummy user is set by default? I believe it should because the Issue Created Event will be fired as the last post-function but I am not sure how Jira handles such changes.

Do you have experience in this?

Thanks!

Like Nic Brough -Adaptavist- likes this
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 1, 2024

They should be, as you say, the event is fired after the issue is built and written to the system.

The way events work is they are a little bundle of information about what just happened.  They go into the event handler queue for listeners and automations to react to, including the notification system.

A create event contains a reference to the new issue, and the new issue has the replacing user on it.  So I would expect them to be notified!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.4.1
TAGS
AUG Leaders

Atlassian Community Events