Originally asked by Syed Majid Hassan on 18 September 2022 (original question)
When syncing chatter feed comments from SF to Jira, the threaded replies in SF are not included in the replica and hence, never sent to Jira. Can you please help with this?
Comments:
Serhiy Onyshchenko commented on 22 September 2022
Hey, Syed Majid Hassan
I’ve added this to the outgoing sync script:
Thanks for the direction here Serhiy Onyshchenko !
The code that I have come up with is the following:
if(entity.entityType == "Case") {
replica.key = entity.Id
replica.summary = entity.Subject
replica.description = entity.Description
replica.attachments = entity.attachments
replica.Status = entity.Status
//Pick up normal SF chatter comments and append the username of the commenter
replica.comments = entity.comments.findAll {
comment ->
def res = httpClient.get("/services/data/v54.0/query/?q=SELECT+Name+from+User+where+id=%27${comment.author.key}%27")
comment.body = nodeHelper.stripHtml(res.records.Name[0] + ": " + comment.body)
}
//Get the feed-element-id of all chatter threads in this case
def feedIds = httpClient.get("/services/data/v54.0/query/?q=SELECT+id+from+CaseFeed+where+ParentId=%27${entity.Id}%27")
//For each chatter thread, read all the replies and append usernames to it
for(int i=0; i<feedIds.records.size(); i++){
def feedResponse = httpClient.getResponse("/services/data/v54.0/chatter/feed-elements/${feedIds.records[i].Id}")
def js = new groovy.json.JsonSlurper()
def feedJson = groovy.json.JsonOutput.toJson(feedResponse.body)
feedResponse.body.capabilities.comments.page.items.collect {
def res = httpClient.get("/services/data/v54.0/query/?q=SELECT+Name+from+User+where+id=%27${it.user.id}%27")
def c = new com.exalate.basic.domain.hubobject.v1.BasicHubComment()
c.body = res.records.Name[0] + " commented: " + it.body.text
c.id = it.id
replica.comments += c
}
}
}
This is working perfectly for sending threaded replies as well as normal comments.