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

Marlene Vitale March 22, 2017

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

4 votes
Answer accepted
Jon Bevan [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.
March 23, 2017

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

Marlene Vitale March 23, 2017

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

Marlene Vitale March 26, 2017

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]
Jon Bevan [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.
March 26, 2017

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