Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Not getting comment as Internal

Khushbu Jowaheer June 10, 2018

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

1 answer

1 accepted

0 votes
Answer accepted
Mark Markov
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.
June 11, 2018

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?

Khushbu Jowaheer June 11, 2018

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.

image.pngimage.png

Mark Markov
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.
June 11, 2018

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!

Khushbu Jowaheer June 11, 2018

Hi Mark,

It Works :) : )...Thanks

Swarna

Mark Markov
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.
June 11, 2018

No problem :) If it help you, mark answer as accepted :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events