Snippets

Adaptavist ScriptRunner For Jira Cloud Create An Issue With A Label From The Script Console

You are viewing an old version of this snippet. View the current version.
Revised by Kristian Walker 1963659
/*
 * This script provides an example script that shows how to create an issue from the Script Console'.
 * 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." 
*/

// Replace Demo below with the ID of your project
def projectKey = 'Demo'
def taskType = get('/rest/api/2/issuetype').asObject(List).body.find { it['name'] == 'Task' }['id']

post('/rest/api/2/issue')
        .header('Content-Type', 'application/json')
        .body(
        [
                fields: [
                        summary    : 'Task Summary',
                        description: "Task Description.",
                        // Replace customfield_12345 with the ID of your custom labels field below
                        customfield_12345: ["ALabel"], // Note the labels field is an array so new labels can be added as a comma seperated list
                        project    : [
                                key: projectKey
                        ],
                        issuetype  : [
                                id: taskType
                        ]
                ]
        ])
        .asString().body
HTTPS SSH

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