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.
Please let me know your thoughts here.
Thanks
Majid
Comments:
Stéphane Thillay commented on 13 July 2023
Hi Majid,
This script works and is useful.
I’m wondering what is the purpose of the line “def js =``newgroovy.json.JsonSlurper()”?
My groovy skill is poor so I may miss the point. It looks like a variable/instance of a class, but it is not used elsewhere in the script.
Regards,
Stéphane
Syed Majid Hassan commented on 06 September 2023
Good catch Stéphane Thillay ,
I believe it was there to parse the response as part of the debugging effort needed in developing the script.