Conditionally add a comment to an issue on transition?

Rob Horan
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.
July 8, 2020

I have been asked to add a post-function that adds a comment to an issue on a transition if a particular field is empty.  I cannot find any way to do this at all.  

I tried to use the code below but this failed with a 'cannot find matching method' error.  In any case, even if I wanted to use scriptrunner, the only way I can see to use this is to use a custom script post-function, which lacks the conditional section.  

I have been searching high and low for an answer but to no avail.  The solution does not need to be scriptrunner, though the only other option I have is JSU and I don't see a way of doing it there.

 

CODE:

import com.atlassian.jira.ComponentManager

import com.atlassian.jira.issue.comments.CommentManager

 

ComponentManager componentManager = ComponentManager.getInstance()

CommentManager commentManager = componentManager.getCommentManager()

 

commentManager.create(issue, transientVars.context.caller, "Comment automatically generated...", false)

2 answers

2 votes
Stefan Forstmoser _beecom_
Contributor
July 10, 2020

Hi @Rob Horan 

with JSU it's super easy to achieve this by combining these two modules:

Fields Required Precondition
Update any Issue Field Post-Function

It will take you less than a minute to configure this. No scripting at all :-)
And you have a solid proven solution without any maintenance hassle.

You can read more about JSU's Preconditions for Post Functions here:
Workflow Preconditions


The completed configuration will look like this:

conditional_comment.png

0 votes
mfabris
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.
July 9, 2020

Hi @Rob Horan 

 

I would notspend too much time trying to script this... 

You could use the excellent automation lite (free plugin) that has if/else blocks and can achieve what you need pretty easily; OR alternatively you could do this, since you have JSU.

1. use the condition "Field Value" from JSU in the "normal" transition and allow it only if the value is in the field (you will use "different to empty")

2. create a second transition between the two statuses; it can have the same name of course; for this you will set the condition that the value is empty  (equal to empty). 

3. In this second transition, you add the comment with the scriptrunner post function for adding a comment.

 

I hope this helps!

Suggest an answer

Log in or Sign up to answer