I am trying to auto-populate "Summary" field based on other custom field values data. I have written the following script.
def issueKey = issue.key
def fields = get('/rest/api/2/field')
.asObject(List)
.body as List<Map>
def cf1 = fields.find { it.name == 'AJW Location' }.id as String
def cfv1 = (issue.fields[cf1] as Map)?.value
def cf2 = fields.find { it.name == 'AJW Area' }.id as String
def cfv2 = (issue.fields[cf2] as Map)?.value
def cf3 = fields.find { it.name == 'A/C Quantity' }.id as String
def cfv3 = (issue.fields[cf3] as Map)?.value
def cfv4 = cfv1 + cfv2 + cfv3
def result = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
summary: cfv4
]
])
.asString()
if (result.status == 204) { (6)
return 'Success'
} else {
return "${result.status}: ${result.body}"
}
I am getting following error.
2019-08-19 03:37:40.784 INFO - Serializing object into 'interface java.util.List' 2019-08-19 03:37:40.794 INFO - GET /rest/api/2/field asObject Request Duration: 877ms 2019-08-19 03:37:40.818 ERROR - No signature of method: java.lang.Double.get() is applicable for argument types: (java.lang.String) values: [value] Possible solutions: getAt(java.lang.String), grep(), next(), grep(java.lang.Object), wait(), abs() on line 14 2019-08-19 03:37:40.853 ERROR - Class: com.adaptavist.sr.cloud.events.WebhookExecution, Config: null
I have configured it as Script Listener for events Issue Created and Issue Updated. It is in Atlassian Cloud.
Hi Pushpkant,
Thank you for your question.
I have reviewed your script and the stack trace for it above and can confirm that it indicates that you are not correctly getting the field values which means that the values cannot be accessed to be added up.
I can confirm that we have an example script of how to get field values and perfrom a calculation when an issue is updated inside of the documentation page located here and would advise that you take this script and use it to achive your requirement of a calculated value on an issue.
If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.
Regards,
Kristian
Hello Kristian,
Now the script is working. Here is the working script for anyone who also faces the same issue.
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
def input1CfId = customFields.find { it.name == 'Field1' }?.id //Select List Field
def input2CfId = customFields.find { it.name == 'Field2' }?.id //Radio Button Field
def input3CfId = customFields.find { it.name == 'Field3' }?.id //Number Field
def outputCfId = customFields.find { it.name == 'Summary' }?.id
def projectKey = "ICF"
def input1 = (issue.fields[input1CfId] as Map)?.value as String
logger.info("Value of Field1 is: ${input1}")
def input2 = (issue.fields[input2CfId] as Map)?.value as String
logger.info("Value of Field2 is: ${input2}")
def input3 = issue.fields[input3CfId] as String
logger.info("Value of Field3 is: ${input3}")
def output = input1 + " - " + input2 + " - " + input3
logger.info("Value of Summary: ${output}")
put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
summary: output
]
])
.asString()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Don't you have to import some library's, or are you just not showing it here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I didn't. I am new to Groovy script development. Kindly help me if I have to include any libraries.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.