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

Accepted Answer
4 votes

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

Looking for anyone who made the switch to Data Center

The Jira Marketing team is putting together an ebook on migrating to Data Center. We're looking for pro tips on how you staffed your project team and organized your Proof of Concept. Share yo...

61 views 0 2
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