Hi,
Hope someone can help me with this error. I created a script to copy the value of AD Manager field to Approvers field through ScriptRunner. However, I keep on getting some errors...
2023-11-27 08:52:23.844 INFO - Serializing object into 'interface java.util.List' 2023-11-27 08:52:23.915 INFO - GET /rest/api/2/field asObject Request Duration: 955ms 2023-11-27 08:52:24.116 ERROR - Cannot get property 'accountId' on null object on line 25 2023-11-27 08:52:24.120 ERROR - Class: com.adaptavist.sr.cloud.events.WebhookExecution, Config: null
My script is this...
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
//to check the listener is only applied to the correct project and issue type
def projectKey = "SIG"
if (issue == null || ((Map) issue.fields.project).key != projectKey || issue.fields.issuetype.name != 'Service Request with Approvals') {
logger.info("Wrong Project ${issue.fields.project.key} or not a SR with Approvals")
return
}
def ADManagerCfId = customFields.find { it.name == 'AD Manager' }?.id
def ApproversCfId = customFields.find { it.name == 'Approvers' }?.id
//get the values from your issues
def ADManager = issue.fields[ADManagerCfId] as Map
def ApproversName = issue.fields[ApproversCfId] as Map
//update the issue with the new approver
put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields: [
"${ApproversCfId}": [ //You need here to interpolate ApproversCfId as a String
['accountId': ADManager.accountId]
]
]
])
.asString()
logger.info ("Updated Approver with ${ADManager.accountId}")Appreciate your suggestion/guidance on how I could fix this error.
Cheers,