/* * This script listiner which should be configured on the issue updated event shows how you can have a field to calculate and show the number of labels on an 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." */// get custom fieldsdefcustomFields=get("/rest/api/2/field").asObject(List).body.findAll{(itasMap).custom}asList<Map>// Specify the Name of the custom type field that will out the calcuated valuedefoutputCfId=customFields.find{it.name=='<NumberFieldNameHere>'}?.id// Specify the project where the calculated field will godefprojectKey="<ProjectKeyHere>"if(issue==null||((Map)issue.fields.project).key!=projectKey){logger.info("Wrong Project \${issue.fields.project.key}")return}// store the number of labelsdefNumberofLabels=(issue.fields.labels.size)intoutput=NumberofLabels.toInteger()if(output==(issue.fields[outputCfId]asInteger)){logger.info("already been updated")return}// Update the issue with the calculated valueput("/rest/api/2/issue/${issue.key}").header("Content-Type","application/json").body([fields:[(outputCfId):output]]).asString()
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.