Hello everybody,
My goal is to migrate some issues from JIRA to JIRA Service Desk. However, I need to set all comments to "Internal" (I do not want my clients to see them). I already got some tips on how to do it here:
Looking on how to get the property and how to use de EntityPropertyService I developed the following code:
def issueManager = ComponentAccessor.getIssueManager() def commentManager = ComponentAccessor.getCommentManager(); def loggedUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService) def issue = issueManager.getIssueObject("MyIssue") def comments = commentManager.getComments(issue) for (def comment : comments) { // Important Part! PropertyInput input = new PropertyInput("{\"internal\":true}", "sd.public.comment") def setResult = commentPropertyService.validateSetProperty(loggedUser, comment.getId(), input) //log.debug setResult.getErrorCollection() //log.debug setResult.isValid() def finalResult = commentPropertyService.setProperty(loggedUser, setResult) //log.debug finalResult.getErrorCollection() //log.debug finalResult.isValid() }
The methods commentPropertyService.validateSetProperty() and commentPropertyService.setProperty() return valid results. No errors caught in getErrorCollection() as well. But my comments are not being updated
Am I doing something wrong? Please help.
JIRA v7.0.0
JIRA Service Desk v3.0.0
Adaptavist ScriptRunner for Jira v4.2.0.1
Community moderators have prevented the ability to post new answers.
Hello all,
After seeing this post https://answers.atlassian.com/questions/32530234, I solved my problem using JsonEntityPropertyManager instead of CommentPropertyService. I hope people from JIRA Service Desk + Script Runner fix this issue in the next release.
I will share with you guys my solution below, a script that sets all comments to internal given a JQL quey.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.Issue import com.atlassian.jira.entity.property.JsonEntityPropertyManager import com.atlassian.jira.bc.issue.search.SearchService import com.atlassian.jira.web.bean.PagerFilter final jqlSearch = "jql" def searchService = ComponentAccessor.getComponent(SearchService.class) def issueManager = ComponentAccessor.getIssueManager() def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def commentManager = ComponentAccessor.getCommentManager(); def jsonManager = ComponentAccessor.getComponent(JsonEntityPropertyManager) //JQL Search List<Issue> issues = null SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch) if (parseResult.isValid()) { def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()) issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)} as List<Issue> } //Setting comments to Internal if (issues) { for (Issue foundIssue : issues) { def comments = commentManager.getComments(foundIssue) for (def comment : comments) { jsonManager.put(user, "sd.comment.property", comment.getId(), "sd.public.comment", "{ \"internal\" : true}" , (java.util.function.BiFunction) null, false) } } }
Regards
Great that you've solved this problem, I will add a similar example to the docs. I don't really understand it though as commentPropertyService uses JsonEntityPropertyManager. Must be something in the args...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Jamie Echlin [Adaptavist]! Tell me if you have any news. I depend on this to install JIRA Service Desk in our company
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I agree that it's not working, but I don't see why. Perhaps there is an additional property it sets. Maybe someone from the JSD team can tell us why, else I'll try and have a look at the source tomorrow.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
is anyone knows how to use commentmanager update method.
if any working example,then it will be better for me,I want to update the existing comment using jira script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.