Hi all,
I will append a generated internal comment by a subtask-transition-postfunction to the parent-task with the following groovy:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.issue.comments.CommentManager import com.atlassian.jira.issue.comments.Comment import com.atlassian.jira.issue.comments.CommentManager import com.atlassian.jira.entity.property.JsonEntityPropertyManager import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService import com.atlassian.jira.user.ApplicationUser import org.apache.log4j.Category import groovy.json.JsonSlurper final SD_PUBLIC_COMMENT = "sd.public.comment" def commentManager = ComponentAccessor.getCommentManager() def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() MutableIssue parentIssue = (MutableIssue)issue.getParentObject() def parentComment = commentManager.create( parentIssue, user, "{color:red}*Prio1 Escalation Request is approved now*{color} with the following comment:\n\n"+transientVars.comment.toString(), false ) log.debug " DEBUG: Comment added for parentIssue " + parentIssue.key + ": Comment.id=" + parentComment.id.toString() // ??? => Don't know the right entityName: "sd.comment.property" or "CommentProperty" (found with commentPropertyService.getProperty..) // Result of commentPropertyService.getProperty..: commentProperty: EntityPropertyImpl[id=10604,entityName=CommentProperty,entityId=10337,key=sd.public.comment,value={"internal":"true"}, // Next line didn't run //JsonEntityPropertyManager.put((ApplicationUser)user, "sd.comment.property", parentComment.id, "sd.public.comment", "{\"internal\":\"true\"}" , (java.util.function.BiFunction) null, false) // Try with deprecated method with less arguments //JsonEntityPropertyManager.put("sd.comment.property", (Long)parentComment.id, "sd.public.comment", "{'internal':'true'}") JsonEntityPropertyManager.put("sd.comment.property", (Long)parentComment.id, SD_PUBLIC_COMMENT, "{'internal':'true'}")
The comment is appended at the parent-issue but the set-to-internal didn't work with the following error:
groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.entity.property.JsonEntityPropertyManager.put() is applicable for argument types: (java.lang.String, java.lang.Long, java.lang.String, java.lang.String) values: [CommentProperty, 10372, sd.public.comment, {'internal':'true'}]
Possible solutions: wait(), any(), dump(), grep(), find(), putAt(java.lang.String, java.lang.Object)
Does anyone has an idea how to fix this? Thanks in advance.
Kind regards
René
Community moderators have prevented the ability to post new answers.
Thank you Jamie and Kristian,
I have solved it with the following script:
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.comments.CommentManager; import com.atlassian.jira.issue.comments.Comment; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService; import com.atlassian.jira.user.ApplicationUser; import com.atlassian.jira.util.json.JSONObject; import groovy.transform.Field; import org.apache.log4j.Logger; import org.apache.log4j.LogManager; final org.apache.log4j.Logger log4jLog = LogManager.getLogger("com.atlassian.jira.groovy"); String logPrefix = "[Approved_Escalation] "; @Field ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() if ( issue.isSubTask() ) { MutableIssue parentIssue = (MutableIssue)issue.getParentObject() if( parentIssue ) { //add comment to parentIssue Map<String, JSONObject> commentPropertyInternal = new HashMap<String, JSONObject>(); commentPropertyInternal.put("sd.public.comment", new JSONObject("{\"internal\":\"true\"}")); def commentManager = ComponentAccessor.getCommentManager() def parentComment = commentManager.create( parentIssue, // Issue issue, currentUser, // ApplicationUser author, "{color:red}*Issue escalated*{color} (Sub-Task ${issue.key})\n\n*{color:#707070}Comment:{color}*\n{color:red}" + transientVars.comment.toString() + "{color}", //String body, null, //String groupLevel, null, //Long roleLevelId, Calendar.getInstance().getTime(), //Date created, commentPropertyInternal, //Map<String,JSONObject> commentProperties, true // dispatchEvent) ) log4jLog.debug(logPrefix + "Comment added for parentIssue : " + parentIssue.key + ": Comment.id=" + parentComment.id.toString()); } }
Thanks
René
You need to get the CommentPropertyService - example here: https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/jira-service-desk.html
You're on the right track.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi René,
Have you looked at the API documentation here, It looks as if you have specified the parameters incorrectly for the method.
It looks as if the parameters should be:
.put(ApplicationUser user, @Nonnull String entityName, @Nonnull Long entityId, @Nonnull String key, @Nullable String json, com.atlassian.fugue.Function2<ApplicationUser,EntityProperty,? extends EntityPropertySetEvent> eventFunction, boolean dispatchEvent)
Thanks
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.