How to Set ‘Internal’ = True when Creating Comment using Issue Service

Kevin Watson March 30, 2018

Whilst I can set the ‘Internal’ property flag using Mutable Issue (from previous forum examples) I’d prefer to use Issue Service if possible, but I’m unable to figure out how to add the property value to the issueInputParameters method.
I've tried searching the forum plus a few variations based on the error responses, but am unable to get it to work.

The error is:
No signature of method: com.atlassian.jira.issue.IssueInputParametersImpl.addProperty() is applicable for argument types: (java.util.HashMap) values: [[sd.public.comment:{"internal":"true"}]]
Possible solutions: addProperty(java.lang.String, org.codehaus.jackson.JsonNode), hasProperty(java.lang.String)

My code is:
Map < String, JSONObject > commentPropertyInternal = new HashMap<String, JSONObject>();
commentPropertyInternal.put("sd.public.comment", new JSONObject("{\"internal\":\"true\"}"));
issueInputParameters.setComment("Created Primary Fix issue")
    .addProperty(commentPropertyInternal)

def update = issueService.validateUpdate(user, issue.id, issueInputParameters)
log.debug "${update}"
if (update.isValid()) {
    issueService.update(user, update)
}

1 answer

1 vote
Henning Tietgens
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.
April 11, 2024

I know, this was asked a long time ago, but maybe this is of use for someone.

To create internal comments using IssueInputParameters you have to provide the correct actionParameters while creating the IssueInputParameters.

import com.atlassian.jira.issue.fields.CommentSystemField
import com.atlassian.jira.component.ComponentAccessor

def issueService = ComponentAccessor.getIssueService()
// as there is no way to set action parameters, this has to be done while
// creating them
def iip = issueService.newIssueInputParameters(getActionParametersForInternalComment())
iip.setComment("Internal comment")
// ...

Map<String, String[]> getActionParametersForInternalComment() {
final String SD_INTERNAL_FIELD_NAME = "internal";
final String SD_JSON_PUBLIC_COMMENT_KEY = "sd.public.comment";

def actionParam = [
(CommentSystemField.PARAM_COMMENT_PROPERTY): ["[{key: \"$SD_JSON_PUBLIC_COMMENT_KEY\", value: {$SD_INTERNAL_FIELD_NAME: \"true\"}}]"] as String[]
]
return actionParam
}

Best,
Henning

Mikey Schott
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 23, 2024

This is awful, and very helpful, and extremely timely. Thank you.

Like Henning Tietgens likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events