How do I assign a ticket based on the reporter ONLY if the assignee field is not selected with a specific user?

We have assignee set to automatic. If someone creates a ticket and leaves it as automatic, it should be assigned to the reporter. If however, the assignee is selected, that should hold. We were using a post-function to assign to reporter, but that will then override if the ticket has been assigned to another person intentionally. We have scriptrunner and can maybe use that to set something up, but I'd like direction to where to help populate that solution.

1 answer

1 accepted

Hi Marlene,

On the Create transition you can add a 'Run Script' post function with the following condition:

issue.fields.assignee == null

And the following code:

def issueKey = issue.key
def result = put("/rest/api/2/issue/${issueKey}")
        .header('Content-Type', 'application/json')
        .body([
                fields: [
                        assignee: [ name: issue.fields.reporter.name ]
                ]
        ])
        .asString()
assert result.status == 200

And that will only set the assignee to the reporter if no assignee has already been selected.

Screen Shot 2017-03-23 at 10.59.30.png

Please note that if you change your project configuration to make the Project Lead the automatic assignee then this code will not override the Project Lead.

Thanks, Jon

This works flawlessly, and can be assigned at any transition as well. Thank you.

Ok, not flawless. While it appears to "work: diagnostics is presenting me with this error - 

CorrelationId: fb59fd5c-7abc-4858-82f5-d5affdd259d4
RUN Script identifier: 15897ebd-62dd-4f1c-82cd-9f1ca95b228b com.adaptavist.sr.cloud.workflow.UpdateIssue ('Create' transition made for issue ITCM-164) Took 1700ms Logs:
2017-03-26 19:15:17.861 INFO - PUT /rest/api/2/issue/ITCM-164 asString Request Duration: 879ms
2017-03-26 19:15:18.082 ERROR - assert result.status == 200
       |      |      |
       |      204    false
       status: 204 - No Content
       body: null on line 10
2017-03-26 19:15:18.120 ERROR - Class: com.adaptavist.sr.cloud.workflow.UpdateIssue, Config: [className:com.adaptavist.sr.cloud.workflow.UpdateIssue, uuid:15897ebd-62dd-4f1c-82cd-9f1ca95b228b, description:Add Assignee if Null, condition:issue.fields.assignee == null, executionUser:INITIATING_USER, additionalCode:def issueKey = issue.key
def result = put("/rest/api/2/issue/${issueKey}")
        .header('Content-Type', 'application/json')
        .body([
                fields: [
                        assignee: [ name: issue.fields.reporter.name ]
                ]
        ])
        .asString()
assert result.status == 200]

Apologies Marlene - at the end of the script I gave you there is an assert to make sure the result.status == 200, that needs changing to assert that result.status == 204

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,338 views 14 20
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot