Hello,
I need to change the visibility of all public comments and add a role restriction to them with ScriptRunner. That's what I have for now:
package com.onresolve.jira.groovy.jql
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.entity.property.JsonEntityPropertyManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def jsonManager = ComponentAccessor.getComponent(JsonEntityPropertyManager)
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def searchText = "issuekey=TSTSUP-1"
def query = jqlQueryParser.parseQuery(searchText)
def results = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
def commentsAll = 0
def issuesAll = []
results.getResults().each {documentIssue ->
MutableIssue mIssue = issueManager.getIssueByCurrentKey(documentIssue.key)
def comments = commentManager.getComments(documentIssue).each {row ->
if (!row.roleLevelId) {
commentsAll++
issuesAll += documentIssue.key
def updateComment = row.body
def commentAuthor = row.authorApplicationUser
def commentDate = row.created
/*first variant*/
commentManager.create(mIssue, commentAuthor, updateComment, null, 10900L, commentDate, false)
commentManager.delete(row)
/*second variant*/
jsonManager.put(user,"comment.property",row.getId(),"visibility","{\"roleLevel\": \"Hidden comments reader\",\"roleLevelId\": \"10900\"}",(java.util.function.BiFunction) null, false)
}
}
}
First variant works well with first comment, but crashed after comment deleting with error:
java.lang.UnsupportedOperationException: Cannot set or mutate an ImmutableGenericValue
Second variant just do nothing. I think problem is in not correct properties naming.
Any help would be appreciated!
Best regards,
evzensx
although I just re-read my code, and I realized that the line for getting task comments should also have Mutable Issue.
results.getResults().each {documentIssue ->
MutableIssue mIssue = issueManager.getIssueByCurrentKey(documentIssue.key)
def comments = commentManager.getComments(mIssue).each {row ->
if (!row.roleLevelId) {
commentsAll++
issuesAll += mIssue.key
def updateComment = row.body
def commentAuthor = row.authorApplicationUser
def commentDate = row.created
commentManager.create(mIssue, commentAuthor, updateComment, null, 10900L, commentDate, false)
commentManager.delete(row)
}
}
}
Looks like it works now.
Everybody thanks for help! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.