Hi ,
I am using script runner to add an internal comment when sub task is closed. When i close a sub task, comment is not marked Internal.
Code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Category
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.util.json.JSONObject
CommentManager commentMgr = ComponentAccessor.getCommentManager()
def issueFactory = ComponentAccessor.getIssueFactory()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
MutableIssue currIssue = issue;
SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
//Collection subTasks = issue.getSubTaskObjects();
MutableIssue parent = issue.getParentObject() as MutableIssue
Collection newSubTask = parent.getSubTaskObjects();
final SD_PUBLIC_COMMENT = "sd.public.comment"
newSubTask.each{
// MutableIssue currIssue = it;
if (currIssue.getStatus().name!= "Closed")
def properties = [(SD_PUBLIC_COMMENT): new JSONObject(["internal": true] as Map)]
log.warn("properties: " + properties)
commentMgr.create(parent,currentUser, "I resolved this issue even though there were unresolved sub-tasks... slapped wrists", null, null, new Date(),properties,true)
}
Log:
2018-06-11 10:35:57,430 WARN [workflow.ScriptWorkflowFunction]: properties: [class:class Script292, binding:org.codehaus.groovy.jsr223.GroovyScriptEngineImpl$1@3c7f94fd]
2018-06-11 10:35:57,439 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2018-06-11 10:35:57,440 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ITSD-3526, actionId: 21, file: <inline script>
java.lang.ClassCastException: java.lang.Class cannot be cast to com.atlassian.jira.util.json.JSONObject
at com.atlassian.jira.issue.comments.DefaultCommentManager.setProperties(DefaultCommentManager.java:509)
at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:269)
at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:206)
at com.atlassian.jira.issue.comments.CommentManager$create$2.call(Unknown Source)
at Script292$_run_closure1.doCall(Script292.groovy:30)
at Script292.run(Script292.groovy:23)
Kindly advice
Thanks and Regards,
Swarna