Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I update an issue comment to Internal using script runner?

phellipe_silva January 13, 2016

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

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
phellipe_silva January 21, 2016

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

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2016

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...

0 votes
phellipe_silva January 13, 2016

Thanks @Jamie Echlin [Adaptavist]! Tell me if you have any news. I depend on this to install JIRA Service Desk in our company

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 13, 2016

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.

Chhaya Gadade September 20, 2018

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.

TAGS
AUG Leaders

Atlassian Community Events