Sync comments when users do not exists in the remote system

Originally asked by Ziad Qadora on 08 December 2020 (original question)


Hi,

I’m trying to sync comments so when the author is present in both system then we do not need to have the sync user info showing by using the below

/*

Sync comments with the original author if the user exists in the local instance
Remove original Comments sync line if you are using this approach
*/
issue.comments = commentHelper.mergeComments(issue, replica){ it.executor = nodeHelper.getUserByEmail(it.author?.email) }

But if the user is not present in the remote system then use

issue.comments = commentHelper.mergeComments(issue, replica)

Is there a way to accomplish this?

Thanks,

Ziad


Answer by Juan Grases on 08 December 2020

Hi, I have an example here that should help you We have integrated ZD with SN but when we push Tickets to Zendesk it is losing people date like Requester/Agent and replacing it with my information in the ZD ticket. (old community)

The idea is that you only add the User prefix if it’s now found:

issue.comments = commentHelper.mergeComments(issue, replica){ comment ->
  comment.executor = nodeHelper.getUserByEmail(comment.author?.email)
  if(comment.executor == null){
     comment.body = "Comment from servicenow by "+comment.author?.username + "\n:" + comment.body
  }
}

Hope it’s helpful.

Juan


Comments:

Ziad Qadora commented on 09 December 2020

Hi Juan,

I get the same error when use the provided error as the one when using the code below

issue.comments = commentHelper.mergeComments(issue, replica){ it.executor = nodeHelper.getUserByEmail(it.author?.email) }

Below is the error

com.exalate.api.exception.script.CreateProcessorException: Script error details: Comment could not be created because FORBIDDEN., you do not have the permission to comment on this issue… Error line: IssueLinks.groovy:774 at com.exalate.error.services.ScriptExceptionCategoryService$.wrapAsCreateProcessorException(ScriptExceptionCategoryService.scala:54) at com.exalate.processor.jira.JiraCreateIssueProcessor.createIssue(JiraCreateIssueProcessor.java:162) at com.exalate.replication.request.CreateIssueSyncRequestState.transition(CreateIssueSyncRequestState.java:73) at com.exalate.replication.request.CreateIssueSyncRequestState.transition(CreateIssueSyncRequestState.java:24) at

Regards,

Ziad

Juan Grases commented on 09 December 2020

That means that the user set on the executor doesn’t have permission to create comments on that issue. We have seen that Jira API blocks customers to create comments for example. Was the user a customer?

Ziad Qadora commented on 09 December 2020

Hi,

The users in this case are vendors who have no access to the remote system. I’m just trying to see if there is way to resolve the issue on hand.

Regards,

Ziad

Ziad Qadora commented on 09 December 2020

Hi,

Correct, but in this case they are vendors who do not have to the remote system.

Regards,

Ziad

Ziad Qadora commented on 11 December 2020

For what I’m trying to do the user need to exist in the local instance

Francis Martens (Exalate) commented on 16 December 2020

Ziad Qadora

What is the current status. Is Juan’s suggestion helping?

Ziad Qadora commented on 16 December 2020

I reverted to the default comment sync because the users have to be on both sides in order to use the solution that Juan suggested.

Francis Martens (Exalate) commented on 16 December 2020

OK - got it.
In the cases where the creation failed because the executor was a customer - are you sure that the customer request type was set on the ticket?