Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner Jira cloud, check the assignee before assigning

George Davies November 20, 2024

Hello, I have a case where on a Script listener I want the action to check if the assignee is account id '999' if it is already 999 then take no action, if the assignee account id is not 999 then assignee the issue to 999. Here is an example of what I have so far, the first section is adding a label before it does this step so don't worry about that part. The only error I am getting is a red underline under the part in Bold.

//Add the label '123'

def issueKey = issue.key
def addLabel = put("/rest/api/2/issue/${issue.key}")
    .header('Content-Type', 'application/json')
    .body([
        update:[
            labels:[
                [
                    add: "label123"
                ]
            ]
        ]
    ])
    .asObject(Map)
//Need to assign to 'joe bloggs' if it isn't already whos account id is 999.

// Get the current assignee
def currentAssigneeResponse = get("/rest/api/2/issue/${issue.key}")
    .header('Content-Type', 'application/json')
    .asObject(Map)

def currentAssignee = issue.assignee.accountId

// Check if the current assignee is already 'Joe Bloggs'
if (currentAssignee != "999") {
    // Change the assignee to 'Joe Bloggs'
    def changeAssignee = put("/rest/api/2/issue/${issue.key}")
        .header('Content-Type', 'application/json')
        .body([
            update:[
                assignee:[
                    [
                        set: [
                            accountId: "999"
                        ]
                    ]
                ]
            ]
        ])
        .asObject(Map)
} else {
    println("The assignee is already Joe Bloggs")
}

 

 

1 answer

1 accepted

4 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 21, 2024

Hi George,

I can confirm with a Script Listener to access fields on an issue you need to call issue.fields.

 

This means your line in bold should change to be like

def currentAssignee = issue.fields.assignee.accountId
I hope this helps.
Regards,
Kristian
George Davies November 21, 2024

Thanks Kristian, that's got it.!

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 21, 2024

Hi George,

I am glad that solved the issue :).

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events