xl8bot
1
Originally asked by Sonal Otwani on 22 September 2023 (original question)
Hi,
I have a connection from Jira On-prime to Salesforce. There are 2 things:
- By default Exalate syncs Jira comments in chatter of salesforce, I want to sync as case comments
- In Jira there are option of private/public comments, I want same behaviour with case comments in Salesforce.
Thanks,
Sonal
xl8bot
2
Answer by Tomas Eduardo Lalanne on 21 May 2024
Hi!
Updating the script for the incoming script in Salesforce.
replica.addedComments.collect { comment ->
def isPublish = comment.internal ? "false" : "true"
def SFCommentId = ""
try {
// Check Exalate documentation for specific HttpClient signature
def headers = ['Content-Type': ['application/json']]
def res2 = httpClient.http( // Call with correct arguments based on documentation
"POST",
"/services/data/v54.0/sobjects/CaseComment",
JsonOutput.toJson([
"CommentBody": "[${comment.author.displayName}] commented : ${nodeHelper.stripHtml(comment.body)}",
"ParentId": "${entity.Id}",
"isPublished": "${isPublish}"
]),
null,
headers
) { req, res2 ->
if (res2.code == 201) {
// Ensure SFCommentId remains a string
SFCommentId = res2?.body?.id?.toString()
} else {
debug.error("Error creating comment: ${res2.code}, Message: ${res2.body}")
}
}
if (SFCommentId) {
def trace = new com.exalate.basic.domain.BasicNonPersistentTrace()
.setType(com.exalate.api.domain.twintrace.TraceType.COMMENT)
.setToSynchronize(true)
.setLocalId(SFCommentId)
.setRemoteId(comment.remoteId as String)
.setAction(com.exalate.api.domain.twintrace.TraceAction.NONE)
traces.add(trace)
}
} catch (Exception e) {
debug.error("An error occurred during comment processing: ${e.message}")
}
}
Thanks
Tomas Lalanne
xl8bot
3
Answer by Sonal Otwani on 22 September 2023
Hey,
Here is the solution which you can put in Salesforce Incoming sync script:
replica.addedComments.collect {
comment ->
def isPublish = "true"
if (comment.internal) {
isPublish = "false"
}
def SFCommentId = ""
def res2 = httpClient.http(
"POST",
"/services/data/v54.0/sobjects/CaseComment",
JsonOutput.toJson(["CommentBody": "[$ {
comment.author.displayName
} ] commented : $ {
nodeHelper.stripHtml(comment.body)
}
" ,
"ParentId" : " $ {
entity.Id
} ", "isPublished": " $ {
isPublish
} " ] ),
null,
null ) {
req ,
res2 ->
if (res2.code == 201) {
SFCommentId = res2?.body?.id
} else {
debug.error("error while creating comment:" + res2.code + " message:" + res2.body)
}
}
if ( SFCommentId ) {
def trace = new com.exalate.basic.domain.BasicNonPersistentTrace()
.setType(com.exalate.api.domain.twintrace.TraceType.COMMENT)
.setToSynchronize(true)
.setLocalId(SFCommentId as String)
.setRemoteId(comment.remoteId as String)
.setAction(com.exalate.api.domain.twintrace.TraceAction.NONE)
traces.add(trace)
}
}
Thanks,
Sonal