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

This widget could not be displayed.

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 Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

292 views 5 0
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