Snippets

Adaptavist Script Listiner Clear description field and different custom field Values When An Issue Is Cloned

Updated by Kristian Walker

File ScriptListinerClearDescriptionFieldAndSingleLineTextFieldValuesWhenAnIssueIsCloned.groovy Modified

  • Ignore whitespace
  • Hide word diff
 /*
-* This example script listner script must bve configured to fire on the 'Issue Link Created' Event and shows how when an issue is cloned that you can clear the value of the description field on the cloned issue. 
-* "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." 
-*/
-
-/*
-* This example script listner script must bve configured to fire on the 'Issue Link Created' Event and shows how when an issue is cloned that you can clear the value of the description field on the cloned issue. 
+* This example script listner script must bve configured to fire on the 'Issue Link Created' Event and shows how when an issue is cloned that you can clear the value of the description field and a single lije text field on the cloned issue. 
 * "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." 
Updated by Kristian Walker

File ScriptListinerClearDescriptionFieldAndSingle Line Text Field ValuesWhenAnIssueIsCloned.groovy Deleted

  • Ignore whitespace
  • Hide word diff
-/*
-* This example script listner script must bve configured to fire on the 'Issue Link Created' Event and shows how when an issue is cloned that you can clear the value of the description field on the cloned issue. 
-* "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." 
-*/
-
-/*
-* This example script listner script must bve configured to fire on the 'Issue Link Created' Event and shows how when an issue is cloned that you can clear the value of the description field on the cloned issue. 
-* "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." 
-*/
-
-// This Script Listiner should be configured to run on the Issue Link Created Event
-
-// Check if the type of the issue link type of the issue is 'Cloners' which is the issue link type that Jira uses when cloning an issue. 
-// If it is a cloned issue then perform the logic to clear field values
-if (issueLink.issueLinkType.name == "Cloners"){ 
-    logger.info("The issue has been cloned so now removing the values from the fields which should not be set")
-    // Below we make a put request to the Issue API to update the issue and to set the fields we want to set to null
-
-    // get custom fields
-    def customFields = get("/rest/api/2/field")
-        .asObject(List)
-        .body
-        .findAll { (it as Map).custom } as List<Map>
-    
-    // Specify the custom field name below for the Single Line Text Field ensuring the < and > characters are removed.
-    def singleLineTextField = customFields.find { it.name == '<SpecifyTheCustomFieldNameHere>' }?.id
-
-    // Note in this example we just set the description to null and you will need to specify any extra fields which you wish to have no value in the 'fields' section of the body for the rest call below.
-    def clearValues = put("/rest/api/2/issue/${issueLink.sourceIssueId}")
-    //.queryString("overrideScreenSecurity", Boolean.TRUE)
-            .header('Content-Type', 'application/json')
-            .body([
-            fields: [
-                    description: null, // set the description to have no value
-                    (singleLineTextField):null
-            ]
-    ])
-            .asString()
-
-// If the issue is not a clone then log a message saying this and do nothing
-}else{
-    logger.info("The issue has not been cloned so do nothing")
-}

File ScriptListinerClearDescriptionFieldAndSingleLineTextFieldValuesWhenAnIssueIsCloned.groovy Added

  • Ignore whitespace
  • Hide word diff
+/*
+* This example script listner script must bve configured to fire on the 'Issue Link Created' Event and shows how when an issue is cloned that you can clear the value of the description field on the cloned issue. 
+* "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." 
+*/
+
+/*
+* This example script listner script must bve configured to fire on the 'Issue Link Created' Event and shows how when an issue is cloned that you can clear the value of the description field on the cloned issue. 
+* "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." 
+*/
+
+// This Script Listiner should be configured to run on the Issue Link Created Event
+
+// Check if the type of the issue link type of the issue is 'Cloners' which is the issue link type that Jira uses when cloning an issue. 
+// If it is a cloned issue then perform the logic to clear field values
+if (issueLink.issueLinkType.name == "Cloners"){ 
+    logger.info("The issue has been cloned so now removing the values from the fields which should not be set")
+    // Below we make a put request to the Issue API to update the issue and to set the fields we want to set to null
+
+    // get custom fields
+    def customFields = get("/rest/api/2/field")
+        .asObject(List)
+        .body
+        .findAll { (it as Map).custom } as List<Map>
+    
+    // Specify the custom field name below for the Single Line Text Field ensuring the < and > characters are removed.
+    def singleLineTextField = customFields.find { it.name == '<SpecifyTheCustomFieldNameHere>' }?.id
+
+    // Note in this example we just set the description to null and you will need to specify any extra fields which you wish to have no value in the 'fields' section of the body for the rest call below.
+    def clearValues = put("/rest/api/2/issue/${issueLink.sourceIssueId}")
+    //.queryString("overrideScreenSecurity", Boolean.TRUE)
+            .header('Content-Type', 'application/json')
+            .body([
+            fields: [
+                    description: null, // set the description to have no value
+                    (singleLineTextField):null
+            ]
+    ])
+            .asString()
+
+// If the issue is not a clone then log a message saying this and do nothing
+}else{
+    logger.info("The issue has not been cloned so do nothing")
+}
Updated by Kristian Walker

File ScriptListinerClearDescriptionFieldAndSingle Line Text Field ValuesWhenAnIssueIsCloned.groovy Added

  • Ignore whitespace
  • Hide word diff
+/*
+* This example script listner script must bve configured to fire on the 'Issue Link Created' Event and shows how when an issue is cloned that you can clear the value of the description field on the cloned issue. 
+* "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." 
+*/
+
+/*
+* This example script listner script must bve configured to fire on the 'Issue Link Created' Event and shows how when an issue is cloned that you can clear the value of the description field on the cloned issue. 
+* "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." 
+*/
+
+// This Script Listiner should be configured to run on the Issue Link Created Event
+
+// Check if the type of the issue link type of the issue is 'Cloners' which is the issue link type that Jira uses when cloning an issue. 
+// If it is a cloned issue then perform the logic to clear field values
+if (issueLink.issueLinkType.name == "Cloners"){ 
+    logger.info("The issue has been cloned so now removing the values from the fields which should not be set")
+    // Below we make a put request to the Issue API to update the issue and to set the fields we want to set to null
+
+    // get custom fields
+    def customFields = get("/rest/api/2/field")
+        .asObject(List)
+        .body
+        .findAll { (it as Map).custom } as List<Map>
+    
+    // Specify the custom field name below for the Single Line Text Field ensuring the < and > characters are removed.
+    def singleLineTextField = customFields.find { it.name == '<SpecifyTheCustomFieldNameHere>' }?.id
+
+    // Note in this example we just set the description to null and you will need to specify any extra fields which you wish to have no value in the 'fields' section of the body for the rest call below.
+    def clearValues = put("/rest/api/2/issue/${issueLink.sourceIssueId}")
+    //.queryString("overrideScreenSecurity", Boolean.TRUE)
+            .header('Content-Type', 'application/json')
+            .body([
+            fields: [
+                    description: null, // set the description to have no value
+                    (singleLineTextField):null
+            ]
+    ])
+            .asString()
+
+// If the issue is not a clone then log a message saying this and do nothing
+}else{
+    logger.info("The issue has not been cloned so do nothing")
+}

File ScriptListinerClearDescriptionFieldWhenAnIssueIsCloned.groovy Deleted

  • Ignore whitespace
  • Hide word diff
-/*
-* This example script listner script must bve configured to fire on the 'Issue Link Created' Event and shows how when an issue is cloned that you can clear the value of the description field on the cloned issue. 
-* "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." 
-*/
-
-/*
-* This example script listner script must bve configured to fire on the 'Issue Link Created' Event and shows how when an issue is cloned that you can clear the value of the description field on the cloned issue. 
-* "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." 
-*/
-
-// This Script Listiner should be configured to run on the Issue Link Created Event
-
-// Check if the type of the issue link type of the issue is 'Cloners' which is the issue link type that Jira uses when cloning an issue. 
-// If it is a cloned issue then perform the logic to clear field values
-if (issueLink.issueLinkType.name == "Cloners"){ 
-    logger.info("The issue has been cloned so now removing the values from the fields which should not be set")
-    // Below we make a put request to the Issue API to update the issue and to set the fields we want to set to null
-
-    // get custom fields
-    def customFields = get("/rest/api/2/field")
-        .asObject(List)
-        .body
-        .findAll { (it as Map).custom } as List<Map>
-    
-    // Specify the custom field name below for the Single Line Text Field ensuring the < and > characters are removed.
-    def singleLineTextField = customFields.find { it.name == '<SpecifyTheCustomFieldNameHere>' }?.id
-
-    // Note in this example we just set the description to null and you will need to specify any extra fields which you wish to have no value in the 'fields' section of the body for the rest call below.
-    def clearValues = put("/rest/api/2/issue/${issueLink.sourceIssueId}")
-    //.queryString("overrideScreenSecurity", Boolean.TRUE)
-            .header('Content-Type', 'application/json')
-            .body([
-            fields: [
-                    description: null, // set the description to have no value
-                    (singleLineTextField):null
-            ]
-    ])
-            .asString()
-
-// If the issue is not a clone then log a message saying this and do nothing
-}else{
-    logger.info("The issue has not been cloned so do nothing")
-}
Updated by Kristian Walker

File ScriptListinerClearDescriptionFieldWhenAnIssueIsCloned.groovy Modified

  • Ignore whitespace
  • Hide word diff
 * amended and must be included in any circumstances where the code snippet is shared by You or a third party." 
 */
 
+/*
+* This example script listner script must bve configured to fire on the 'Issue Link Created' Event and shows how when an issue is cloned that you can clear the value of the description field on the cloned issue. 
+* "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." 
+*/
+
 // This Script Listiner should be configured to run on the Issue Link Created Event
 
 // Check if the type of the issue link type of the issue is 'Cloners' which is the issue link type that Jira uses when cloning an issue. 
     logger.info("The issue has been cloned so now removing the values from the fields which should not be set")
     // Below we make a put request to the Issue API to update the issue and to set the fields we want to set to null
 
+    // get custom fields
+    def customFields = get("/rest/api/2/field")
+        .asObject(List)
+        .body
+        .findAll { (it as Map).custom } as List<Map>
+    
+    // Specify the custom field name below for the Single Line Text Field ensuring the < and > characters are removed.
+    def singleLineTextField = customFields.find { it.name == '<SpecifyTheCustomFieldNameHere>' }?.id
+
     // Note in this example we just set the description to null and you will need to specify any extra fields which you wish to have no value in the 'fields' section of the body for the rest call below.
     def clearValues = put("/rest/api/2/issue/${issueLink.sourceIssueId}")
     //.queryString("overrideScreenSecurity", Boolean.TRUE)
             .header('Content-Type', 'application/json')
             .body([
             fields: [
-                    description: null // set the description to have no value
+                    description: null, // set the description to have no value
+                    (singleLineTextField):null
             ]
     ])
             .asString()
Updated by Kristian Walker

File ScriptListinerClearDescriptionFieldWhenAnIssueIsCloned.groovy Modified

  • Ignore whitespace
  • Hide word diff
 */
 
 // This Script Listiner should be configured to run on the Issue Link Created Event
-if (issueLink.issueLinkType.name == "Cloners"){
+
+// Check if the type of the issue link type of the issue is 'Cloners' which is the issue link type that Jira uses when cloning an issue. 
+// If it is a cloned issue then perform the logic to clear field values
+if (issueLink.issueLinkType.name == "Cloners"){ 
     logger.info("The issue has been cloned so now removing the values from the fields which should not be set")
     // Below we make a put request to the Issue API to update the issue and to set the fields we want to set to null
 
  1. 1
  2. 2
  3. 3
HTTPS SSH

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