/** This example script console script takes the value from a text field on an issue and copies it to a new comment on the 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." */// Specify the issue key heredefissueKey='<IssueKeyHere>'// Fetch the issue object from the keydefissue=get("/rest/api/2/issue/${issueKey}").header('Content-Type','application/json').asObject(Map).body// Get all the fields from the issue as a Mapdeffields=issue.fieldsasMap// Get the Custom field to get the value fromdefcustomField=get("/rest/api/2/field").asObject(List).body.find{(itasMap).name=='<CustomFieldNameHere>'// Specify the custom field name here}asMap// Save the value of the text field to a variabledeftextFieldValue=(fields[customField.id]asString)?.value// check if the value for the text field is not nullif(textFieldValue){// Add a comment to the issue showing the value saved for this field. defcommentResp=post("/rest/api/2/issue/${issueKey}/comment").header('Content-Type','application/json').body([body:"""The value from the ${customField.name} custom field has been added to this comment and is the value below: ${textFieldValue} """]).asObject(Map)}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.