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
Hello @Khushbu Jowaheer
I check you code and it work pretty well.
It seems like groovy do not cast objects properly
try to replace def properties with
Map properties = [(SD_PUBLIC_COMMENT): new JSONObject(["internal": true] as Map)]
And your code is too complicated for your goal.
What are tryin to achieve? As i understand you want to add comment to parent issue when subtask is closed and there are another unresolved subtasks. And this is postfunction in subtasks workflow.
Am I right?
Hi Mark,
As you mentioned, each time a sub task is closed, a comment is added to parent issue. I have changed the code above. The issue is still the same. Customer are able to view the comment in their request that y i want the comment to be internal. Please see screenshot.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this code bellow :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.util.json.JSONObject
final SD_PUBLIC_COMMENT = "sd.public.comment"
def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def parent = issue.getParentObject() as MutableIssue
def properties = [(SD_PUBLIC_COMMENT): new JSONObject(["internal": true] as Map)]
log.warn("properties: " + properties)
def subtasks = parent.getSubTaskObjects()
if (subtasks.find {it.status.name != "Done"}){
commentManager.create(parent,user, "I resolved this issue even though there were unresolved sub-tasks... slapped wrists", null, null, new Date(),properties,true)
}
this is postfunction on subtasks workflow. On transition that goes to "Done" status
I check it on ScriptRunner v5.4.7 and it works!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem :) If it help you, mark answer as accepted :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.