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!
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
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?
This one did it for me:
import com.atlassian.jira.issue.Issue;import com.atlassian.jira.issue.attachment.Attachmentimport com.atlassian.jira.component.ComponentAccessor;import com.atlassian.jira.bc.issue.search.SearchServiceimport com.atlassian.jira.web.bean.PagerFilterimport com.atlassian.jira.issue.search.SearchQueryimport com.atlassian.jira.issue.comments.CommentManagerimport com.atlassian.jira.user.ApplicationUserimport 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.JsonEntityPropertyManagerdef findIssues(String jqlQuery) {def issueManager = ComponentAccessor.issueManagerdef 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 commentsdef 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)}}
It looks like you're new here. Sign in or register to get started.