Questions for Confluence license has expired.

Please purchase a new license to continue using Questions for Confluence.

Resolution sync issue - Cannot get property name on null object

 
1
0
-1

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
}
  1. Ariel Aguilar

    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

  2. Archita Gupta

    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

  3. Archita Gupta

    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.
CommentAdd your comment...

1 answer

  1.  
    1
    0
    -1

    //This is the definition in the Jira instance Incoming sync connection


    def remoteStatusName = replica.status.name


    def statusMap = ["Open":"Open", "Work in Progress":"In Progress",
    "Pending":"Needs Info", "Closed Complete":"Resolved",
    "Resolved": "Resolved" , "In Progress":"In Progress","New":"Open", "On Hold":"Needs Info", "Canceled":"Closed", "Closed":"Closed"]

    if (replica.status == null ||
        replica.status.name == null ||
        statusMap.get(replica.status.name) == null) {
      issue.comments = commentHelper.addComment("Remote status is unknown or cannot be mapped - can't handle it", issue.comments)

    else if (replica.status.name == "Resolved" ){
      issue.resolution = nodeHelper.getResolution("Fixed")
    }
    else if (replica.status.name == "Closed" ){
      issue.resolution = nodeHelper.getResolution("Done")
    }
    else {
      issue.setStatus(statusMap[replica.status.name])
      

    if (replica.resolution == null) {
       // if the remote issue is not resolved
       issue.resolution = null
    }
      
    if (replica.resolution != null) {
       // the remote issue is resolved, but the local isn't - look up the correct local resolution object.
     
     
       def resolutionMap = [
            "Solved" : "Done",
            "Closed/Resolved by Requester" : "Won't Do",
            "Not Solved" :  "Won't Fix"
       ]
       // use 'done' as resolution if the remote resolution is not found
       def targetResolutionName = resolutionMap[replica.resolution.name] ?: "Done"
        
       // nodeHelper.getResolution looks up the local resolution object based on the provided name
       issue.resolution = nodeHelper.getResolution(targetResolutionName)
    }
     

      CommentAdd your comment...