Originally asked by Archita Gupta on 24 September 2021 (original question)
To sync the resolution from Jira to ServiceNow, I have written below code in the incoming sync of SNOW. It was working before. However, when I retested, it gave me error in the line #9 - Cannot get property name on null object.
if(entity.tableName == "incident") {
entity.close_notes = "Resolved in Jira"
entity.close_code = replica.resolution
def resolutionMap = [
"Done" : "Solved",
"Won't Do" : "Closed/Resolved by Requester",
"Known Error" : "Not Solved"
]
def targetResolutionName = resolutionMap[replica.resolution.name] ?: "Solved" //issue in this line
entity.close_code = resolutionMap[targetResolutionName] ?: targetResolutionName //close_code is name of the field (Resolution code) in SNOW.
entity.save
}
Comments:
Ariel Aguilar commented on 24 September 2021
Hi Archita,
Is there a chance the issue that caused the error, did not have any value matching the resolutionMap? Then if the value is coming ânullâ you can try:
if(entity.tableName == "incident") {
entity.close_notes = "Resolved in Jira"
entity.close_code = replica.resolution
def resolutionMap = [
"Done" : "Solved",
"Won't Do" : "Closed/Resolved by Requester",
"Known Error" : "Not Solved"
]
def targetResolutionName = resolutionMap[replica.resolution?.name?] ?: "Solved" //***this was the only line modified***
entity.close_code = resolutionMap[targetResolutionName] ?: targetResolutionName //close_code is name of the field (Resolution code) in SNOW.
entity.save
}
Let me know if this works for you.
Kind regards,
Ariel
Archita Gupta commented on 24 September 2021
Hi Ariel,
Thanks for your response. I added your changes and now getting below error.
'Script cannot be saved. Details: startup failed: Script408.groovy: 34: unexpected token: ? @ line 34, column 70. onMap[replica.resolution?.name?] ?: "Sol ^ 1 error â
Regards,
Archita
Archita Gupta commented on 28 September 2021
Ariel,
I removed the extra question mark after name and it worked.
def targetResolutionName = resolutionMap[replica.resolution?.name] ?: "Solved"
However, this is my outgoing sync and is throwing error which is why
state in Jira is not changing to Resolved and resolution code is not syncing
Can you help?
replica.resolution = entity.close_code
close_code is the internal name for Resolution code.