Add Comment with Dynamic Field Values To Issue with Script Runner

Frank Stillone February 22, 2018

Hi there,

would like to add a comment into a workflow on transition but would like that comment to be the same every time with the exception that some data from the issues is used in the comment such as CurrentAssignee and NewAssignee.

I have used this script and it works fine

---

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import org.apache.log4j.Category

String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
commmgr = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class)
commmgr.create(issue, currentUser, "I resolved this issue even though there are unresolved sub-tasks... slapped wrists", true)
issue.store()

---

but I would like to add carriage returns and variables like this

---

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import org.apache.log4j.Category

String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
commmgr = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class)
commmgr.create(issue, currentUser, "$NewAssigneeFirstName$,

Please proceed with this task. Please revert back if you have any questions.

Thanks,

$CurrentAssigneeFirstName", true)
issue.store()

---

Could you please tell me how I would achieve this result,

Thanks

Frank

 

 

1 answer

0 votes
Ivan Tovbin
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.
February 22, 2018

Hi Frank,

You've actually almost did it yourself! You can cast variables into a string using GStrings, like so:

String sampleString = "This issues's key is ${issue.getKey()}"

This example will return: "This issue's key is ABC-123"

Frank Stillone February 22, 2018

Thanks Ivan,

I can't take credit for that script above - I found that at https://scriptrunner.adaptavist.com/

thanks for the input - I will test and see how I go,

cheers

Frank

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events