We are trying to set value for close code field in SNOW whose value depends on value of field Cancelation reason in JIRA. for example: if issues status is Canceled in Jira and value of cancellation reason in Jira is “Canceled by Client” then value of fields close code and close note in snow should be updated.
Answer by Francis Martens (Exalate) on 28 August 2020
Can you check if the if branch is being reached by adding something like
//Status Mapping
def statusMap = ["Done": "Resolved","Canceled": "Resolved","Impediment": "Awaiting User Info"]
def remoteStatusName = replica.status.name
issue.setStatus(statusMap[remoteStatusName] ?: remoteStatusName)
if (replica.status.name == "Done") {
incident.close_notes = "Resolution notes in JIRA"
incident.close_code = "Solved (Permanently)"
}
// Show some variables in the error
throw new Exception("Replica.status.name == ${replica.status.name}, replica.customFields."Cancellation Reason".value == ${replica.customFields."Cancellation Reason".value}")
if (replica.status.name == "Canceled") {
if (replica.customFields."Cancellation Reason".value == "Canceled by client"){
incident.close_notes = "Canceled by customer"
incident.close_code = "Not Solved (canceled by customer)"
}
You need to have a pending incoming sync to trigger the exception.
If this shows the wrong value - dive into that section, if it shows the right value - add a throw in the if branch
//Status Mapping
def statusMap = ["Done": "Resolved","Canceled": "Resolved","Impediment": "Awaiting User Info"]
def remoteStatusName = replica.status.name
issue.setStatus(statusMap[remoteStatusName] ?: remoteStatusName)
if (replica.status.name == "Done") {
incident.close_notes = "Resolution notes in JIRA"
incident.close_code = "Solved (Permanently)"
}
if (replica.status.name == "Canceled") {
if (replica.customFields."Cancellation Reason".value == "Canceled by client"){
// Show that the branch is reached
throw new Exception("Now in the right branch")
incident.close_notes = "Canceled by customer"
incident.close_code = "Not Solved (canceled by customer)"
}
If the branch is reached - check that there are no permission restrictions on the field (that is possible in the servicenow).
If there are permission restrictions - clear them for the proxy user
Try again