How to sync Default Reason Code in DevOPs to Zendesk

Originally asked by Jeff Roncone on 04 November 2022 (original question)


I am trying to sync workItem.‘Microsoft.VSTS.Common.ResolvedReason’ from Azdo to ZenDesk custom Field

I am getting an error No such property: previous for class: Script49 @ line 52

if (previous.status.name == "Active" && issue.customFields."Azdo Reason".value == "Fixed and verified" && replica.status.name == "Closed")

Azdo Outgoing:

/* groovylint-disable LineLength */
replica.key            = workItem.key
replica.assignee       = workItem.assignee 
//replica.summary        = workItem.summary
//replica.description    = nodeHelper.stripHtml(workItem.description)
//replica.type           = workItem.type
replica.status         = workItem.status
replica.labels         = workItem.labels
replica.priority       = workItem.priority
//send all users  comments except Azdo Intergrate-Exalate
replica.comments       = nodeHelper.stripHtmlFromComments(issue.comments.findAll { comment -> comment.author.displayName != "Azdo Intergrate-Exalate" })
//replica.comments       = nodeHelper.stripHtmlFromComments(workItem.comments)
//replica.attachments    = workItem.attachments
//replica.project        = workItem.project
//replica.areaPath       = workItem.areaPath
//replica.iterationPath  = workItem.iterationPath
replica.Reason         = workItem."System.Reason"
//replica.customFields."Resolved Reason"    = workItem."Resolved Reason"
replica.customFields."Resolved Reason"    = workItem.'Microsoft.VSTS.Common.ResolvedReason'


//Send a Custom Field value
replica.customFields."Planned Release Date" = workItem.customFields."Planned Release Date"

ZD Incoming

ZD Incoming Expand source

// ZD- Incoming

issue.labels  = replica.labels
issue.summary      = replica.summary
issue.description  = replica.description ?: "No description"
//issue.attachments  = attachmentHelper.mergeAttachments(issue, replica)


issue.customFields."Planned Release Date".value = replica.customFields."Planned Release Date".value
//debug.error("${replica.customFields."Planned Release Date".value}")
//issue.customFields."Azdo Reason".value = replica.Reason
issue.customFields."Azdo Status".value = replica.status?.name
issue.customFields."Azdo Reason" = replica.customFields."Resolved Reason"
//debug.error("${replica.customFields."Reason".value}")


def statusMapping = ["Closed": "solved", 
                     "Open":"New", 
                     "Blocked-Customer" : "pending"]
def remoteStatusName = replica.status.name


issue.setStatus(statusMapping[remoteStatusName] ?: "open")


 /*def typeMap = [
     "Bug" : "bug",
     "User Story" : "user_story",
     ]
    def targetType = typeMap[replica.type]
      issue.customFields."Azdo Type"?.value = targetType
*/

/*
if (remoteStatusName == "Done")  {
   issue.comments = commentHelper.addComment("This ticket is resolved", issue.comments)
} else {
  issue.comments     = commentHelper.mergeComments(issue, replica)
}
*/

/*
//If then else for Public comments on status change
if (previous.status.name == "New" && replica.status.name == "Closed")
      issue.comments = commentHelper.addComment(issue.comments){comment ->
   comment.internal = false
   comment.body = "This ticket has been completed."}
  else {
  issue.comments     = commentHelper.mergeComments(issue, replica)
}  
*/
if (previous.status.name == "Active" && issue.customFields."Azdo Reason".name == "Fixed and verified" && replica.status.name == "Closed")
   issue.comments = commentHelper.addComment(issue.comments){comment ->
   comment.internal = false
   comment.body = "A new software release has been deployed to your database. The updated version resolves the incident reported on this ticket. Kindly take a moment to verify this in your system. Should you discover this behavior is still occurring, please comment on this ticket so we can inform our Product & Development Teams. Thank you for remaining a valued partner with Avionté."}
   
   else if (previous.status.name == "Ready for Demo" && issue.customFields."Azdo Reason".value == "Fixed and verified" && replica.status.name == "Closed")
   issue.comments = commentHelper.addComment(issue.comments){comment ->
   comment.internal = false
   comment.body = "This ticket has been completed."}
   
   else if (previous.status.name == "Ready to Release" && issue.customFields."Azdo Reason".value == "Fixed and verified" && replica.status.name == "Closed")
   issue.comments = commentHelper.addComment(issue.comments){comment ->
   comment.internal = false
   comment.body = "This ticket has been completed."}
   
   else if (previous.status.name == "Ready to Deploy" && issue.customFields."Azdo Reason".value == "Fixed and verified" && replica.status.name == "Closed")
   issue.comments = commentHelper.addComment(issue.comments){comment ->
   comment.internal = false
   comment.body = "This ticket has been completed."}
   
   else if (previous.status.name == "Blocked-Customer" && issue.customFields."Azdo Reason".value == "Fixed and verified" && replica.status.name == "Closed")
   issue.comments = commentHelper.addComment(issue.comments){comment ->
   comment.internal = false
   comment.body = "This ticket has been completed."}
   
   else if (previous.status.name == "Product Review" && issue.customFields."Azdo Reason".value == "Fixed and verified" && replica.status.name == "Closed")
   issue.comments = commentHelper.addComment(issue.comments){comment ->
   comment.internal = false
      comment.body = "This ticket has been completed."}
   
   
   else if (issue.customFields."Azdo Type"?.value == "user_story"){
    issue.comments = commentHelper.addComment("", issue.comments)
       
   }

   else {  
  issue.comments     = commentHelper.mergeComments(issue, replica)
}  
  



Comments:

Jose Pablo Alpizar Hidalgo commented on 17 November 2022

May you please send me the full stack trace of the error message?