Hi,
Looking for a script to change the comment visibility of an issue in JSD.
The comments need to be hidden from the customer after doing a migration and import via csv file.
Thanks!
This one did it for me:
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.search.SearchQuery
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.issue.search.SearchResults;
import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.issue.AttachmentManager;
import com.atlassian.jira.entity.property.JsonEntityPropertyManager
def findIssues(String jqlQuery) {
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.getUserManager().getUserByKey("no-reply")
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchService = ComponentAccessor.getComponent(SearchService)
def query = jqlQueryParser.parseQuery(jqlQuery)
def results = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
results.getResults()
}
def user = ComponentAccessor.getUserManager().getUserByKey("no-reply")
long INTERNAL_USERS_ROLE_ID = 10000l;
def jqlQuery = "project = sd10 and status = 'In Progress'"
def issues = findIssues(jqlQuery)
def commentManager = ComponentAccessor.getCommentManager()
def jsonManager = ComponentAccessor.getComponent(JsonEntityPropertyManager)
issues.each{issue ->
log.error("Changing comment visibility on $issue.")
// Get all comments
def comments = commentManager.getComments(issue);
for (def comment : comments) {
jsonManager.put(user, "sd.comment.property", comment.getId(), "sd.public.comment", "{ \"internal\" : true}" , (java.util.function.BiFunction) null, false)
}
}
Hi,
Thanks for you reply, however, my problem is different in this because we need to change already existing comments.
These comments are created when importing issues via the CSV import and there it's not possible to set it comment to internal only.
So how can we change already existing comments using a groovy script?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We run across a very similar issue and the resolution/script was provided by Andy Heinzer in this thread.
Basically:
{
"update": {
"comment": [
{
"add": {
"public": false,
"body": "Ticket automatically resolved upon creation"
}
}
]
}
}
{
"update": {
"comment": [
{
"add": {
"body": "Thanks for raising {{issue.key}}.",
"visibility": {
"type": "role",
"value": "Developers"
}
}
}
]
}
}
In this case, as Andy mentioned as well, you'd need to update the actor of your automation to a user that belongs to the Role/Group you are restricting the comment visibility to. The reason is that the standard automation user "Automation for Jira" is not part of that role and therefore cannot publish restricted comments to that role.
I hope this helps. Let me know if it doesn't
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.