Snippets

Adaptavist Add or Update Assignee according to option selected from List

Created by Ram Kumar Aravindakshan last modified Kristian Walker
/*
 * All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner
 * license shall be granted a  non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed
 * or amended and must be included in any circumstances where the code snippet is shared by You or a third party."
*/

// Specify the issue key of the issue to update below
def issueKey = '<ISSUE_KEY>'

def output = [:]

def result = get("/rest/api/2/issue/${issueKey}").header('Content-Type', 'application/json').asObject(Map)

if (result.status == 200){
   output =  result.body.fields
} 

//Set the Number field ID
def number1 = output.get('<NUMBER_FIELD_ID>') as Integer

//Set Multi-User Picker ID
def multiUserField = '<MULTI_USER_PICKER_ID>'.toString()

if(number1 == <NUMBER_FIELD_VALUE>) {
 def setMultiUserPicker = put("/rest/api/2/issue/${issueKey}")
        .header('Content-Type', 'application/json')
        .queryString('overrideScreenSecurity', Boolean.TRUE)
        .body([
            // Specify the update structure to update the Multi Select list field and its Array List Data Structure that it uses
            update:
                [
                    (multiUserField): [
                        // Specify the add commands to add each user into the Array List structure for the field using their accountId
                        // Comma seperate the add commend for each user you want to add using their accountId
                            [add: [accountId: '<USER_ACCOUNT_ID>']]
                        
                        ]
                
                ]
        ])
        .asString()
        .body  
        
        return "Issue with the key of ${issueKey} updated with the Multi User Picker Field set on it"  
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.