Snippets

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

Updated by Kristian Walker

File ScriptRunnerForJiraCloudCreateAnIssueWithALabelFromTheScriptConsole.groovy Modified

  • Ignore whitespace
  • Hide word diff
                 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
+                        // Replace customfield_10100 with the ID of your custom labels field below
+                        customfield_10100: ["ALabel"], // Note the labels field is an array so new labels can be added as a comma seperated list
                         project    : [
                                 key: projectKey
                         ],
Updated by Kristian Walker

File ScriptRunnerForJiraCloudCreateAnIssueWithALabelFromTheScriptConsole.groovy Modified

  • Ignore whitespace
  • Hide word diff
         [
                 fields: [
                         summary    : 'Task Summary',
-                        description: "Don't forget to do this!.",
+                        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    : [
Updated by Kristian Walker

File ScriptRunnerForJiraCloudCreateAnIssueWithALabelFromTheScriptConsole.groovy Modified

  • Ignore whitespace
  • Hide word diff
+/*
+ * 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']
                         summary    : 'Task Summary',
                         description: "Don't forget to do this!.",
                         // Replace customfield_12345 with the ID of your custom labels field below
-                        customfield_12345: ["ALabel"],
+                        customfield_12345: ["ALabel"], // Note the labels field is an array so new labels can be added as a comma seperated list
                         project    : [
                                 key: projectKey
                         ],
Created by Kristian Walker

File ScriptRunnerForJiraCloudCreateAnIssueWithALabelFromTheScriptConsole.groovy Added

  • Ignore whitespace
  • Hide word diff
+// 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: "Don't forget to do this!.",
+                        // Replace customfield_12345 with the ID of your custom labels field below
+                        customfield_12345: ["ALabel"],
+                        project    : [
+                                key: projectKey
+                        ],
+                        issuetype  : [
+                                id: taskType
+                        ]
+                ]
+        ])
+        .asString().body
HTTPS SSH

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