For a transition I want to automatically create a comment to the issue as a post function and use information from the issue itself within the generated comment.
The following expression represents pseudo-code:
{User_how_causes_the_transition} has approved to grant {Custom_Field_ID_1234} the privilege {Custom_Field_ID_5678}.
{Assignee}: Please issue the privilege now.
I see myself infront of the Jira "Add Parameters To Function" dialog with "Comment type" set to "Groovy Expression".
What do I have to enter into the "Value"?
I could not find a list containing what options do I have with Groovy within Jira. Ok, there is an "You can use the following variables in your Groovy script" line but how do I know what properties of the objects are available?
Ok, let's try this again.
Create a scripted post-function on the transition which you want to generate a comment using the code below. I'm going to assume that this comment should be posted on behalf the user who triggered this transition (e.g. the supervisor?)
import com.atlassian.jira.component.ComponentAccessor
def commentMgr = ComponentAccessor.getCommentManager()
def cfMgr = ComponentAccessor.getCustomFieldManager()
def cf1Value = issue.getCustomFieldValue(cfMgr.getCustomFieldObject(1234 as Long))
def cf2Value = issue.getCustomFieldValue(cfMgr.getCustomFieldObject(5678 as Long))
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser()
commentMgr.create(issue, currentUser, "${currentUser.getDisplayName()} has approved to grant ${cf1Value} the privilege ${cf2Value}. ${issue.getAssignee().getDisplayName()}: Please issue the privilege now." as String, true)
Hi Soren,
Assuming {User_how_causes_the_transition} is always the name of the current logged in user and {Custom_Field_ID_1234} and {Custom_Field_ID_5678} are values of respective custom fields, the code should look something like this:
import com.atlassian.jira.component.ComponentAccessor
def cfMgr = ComponentAccessor.getCustomFieldManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getDisplayName()
def cf1 = issue.getCustomFieldValue(cfMgr.getCustomFieldObject(1234))
def cf2 = issue.getCustomFieldValue(cfMgr.getCustomFieldObject(5678))
return "${currentUser} has approved to grant ${cf1} the privilege ${cf2}. ${issue.getAssignee().getDisplayName()}: Please issue the privilege now." as String
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you! I will try your snippet in a minute or so.
Do you have a reference list for "all the properties" of e.g. "ComponentAccessor" or "issue"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
DistributionDocumentation
JIRA Server | |
JIRA Cloud | Latest version |
DistributionDocumentation
JIRA Software Server | All versions |
DistributionDocumentation
JIRA Service Desk Server | Latest production version |
JIRA Service Desk Server | All versions |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got the following error while creating an issue:
Property 'currentUser' not found
PS: Jira version is 6.3.5
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Incidentally, which addon are you using to create this post-function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For 6.3.5 try changing 'getLoggedInUser()' to 'getUser()' in the 'currentUser' variable definition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am assuming Groovy post-function comments is provided by Adaptavist ScriptRunner for JIRA (4.1.3.14), but I am not sure (just taken over the administration).
And changing it to "getUser" won't help.
The error says it could not find the property (the variable we defined). I tried to change it from "def" to "String" but this also not worked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's odd. Could you describe your use case more thoroughly?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your help and sorry for the delay.
The workflow describes a permission granting process in which different transitions have different conditions on which group of users may able to use the transitions.
Hopefully I could explain the use case your way so you can follow my thoughts ;)
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.