I’ve build a script for my incoming Jira, It’s all working fine including asset filed being populated or mostly!
The issue I’m having is the asset fields (Direct API Method) is that on creation these get missed as the issue id doesn’t exist so I’ve used:
if (firstSync) {
issue.projectKey = "DCS"
issue.type = nodeHelper.getIssueType(replica.type?.name, issue.projectKey) ?: nodeHelper.getIssueType("Incident", issue.projectKey)
issue.customFields."Link to ZenDesk".value = remoteIssueUrl
issue.summary = replica.summary
issue.description = replica.description
issue.comments = commentHelper.mergeComments(issue, replica)
// Other custom field code
// Trigger a second pass to handle Assets after the issue is indexed
syncHelper.syncBackAfterProcessing()
return
}
Then the asset filed one of 3 I have
// --- Platform Sync (Direct API Method) ---
try {
def remoteVal = (replica.customFields."Org Platform"?.value?.value ?: replica.customFields."Org Platform"?.value)?.toString()
def workspaceId = "7d677423-68d8-4038-87eb-2f9f745855db"
if (remoteVal) {
def assetMap = [
"platform-field_acorn" : "37",
"platform-field_banking-live" : "35",
"platform-field_voucherengine" : "36",
"platform-field_not-applicable" : "845"
]
def targetId = assetMap[remoteVal.trim()] ?: "845"
// Construct the raw JSON payload Jira requires for Assets
def jsonBody = """
{
"update": {
"customfield_11995": [
{
"set": [
{
"workspaceId": "${workspaceId}",
"id": "${workspaceId}:${targetId}",
"objectId": "${targetId}"
}
]
}
]
}
}
"""
// Send the update directly to the Jira Issue API
def response = httpClient.put("/rest/api/3/issue/${issue.key}", jsonBody)
if (response.status != 204 && response.status != 200) {
log.error("Asset API Update Failed: ${response.body}")
} else {
log.info("Successfully forced Asset update for ${issue.key}")
}
}
} catch (Exception e) {
// Add Error to the syncErrors List, so an internal comment can by added to the ticlet at the end of the sync
//syncErrors.add("Automatic Sync Notification: Platform Sync failed. Error: ${e.message}")
// Logs the error in the Exalate Admin Panel
log.error("Automatic Sync Notification: Platform Sync failed. Error: " + e.message)
}
But it fails every time on creation, if anyone can help please.
Regards
Matt