Workflow transition post function ScriptRunner condition help

Daniel Sabeti November 7, 2017

Hey everyone!

Long time lurker, first time poster ;)

Trying to add a post function to a workflow transition (Script Post-Function -> "Fires an event when condition is true"), and I need your help with writing up a condition that will check to see if a comment was added during the transition. If that condition is met, it'll fire the event.

Any info/direction would be greatly appreciated!

3 answers

1 accepted

3 votes
Answer accepted
Joshua Yamdogo @ Adaptavist
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.
November 13, 2017

Hi Daniel,

I think @Alexey Matveev essentially gave you the correct answer, but you just need to apply it as a post-function that fires a condition when true and not strictly as a validator. For example, your condition would be this:

if (transientVars.get("comment")) {
log.debug("User has entered a comment on the transition screen.")
return true
}

 Screen Shot 2017-11-13 at 4.00.38 PM.pngPlease note: just ignore the static type checking error, as the script will still work.

I have tested it successfully and can see it's working from the output in the logs:

[scriptrunner.jira.workflow.ScriptWorkflowFunction] User has entered a comment on the transition screen.
[jira.workflow.postfunctions.FireEventWhen] Raising event: 2
Daniel Sabeti November 13, 2017

Perfect, that's exactly what I was looking for, and confirmed working on our end as well! Thank you so much, Joshua, you're a life saver!! :D

1 vote
Alexey Matveev
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.
November 7, 2017

Hello, 

I guess you can not achieve it with a post function. You can check if a comment was added in a validator. The code for the validator would be something like this:

if (transientVars.get("comment")) { ... }

What is your business requirement? Maybe there is another solution

Daniel Sabeti November 8, 2017

Thank you for following up, Alexey! From what I understand, if I set up a validator for the transition (to check if a comment was added), when no comment is added, it will not complete the transition - is that correct? If that's the case, then a validator may not be what I'm looking for.

To explain, the business requirement is limiting the number/type of notifications that go out to our assignees, as right now, any event we set to the transition (i.e. Issue Commented, Generic Event, etc.) will fire off a notification regardless of whether or not a comment was added. What we want is to only send notifications for specific transitions that have a comment field attached to their screens when a comment is added.

Alternatively, I guess it would also work if we could remove the comment field from those transitions, but from everything I've tried (both through the Screens/Screen Schemes section and through the properties for the transition itself), that doesn't appear to be possible. Ideally, it would be possible to do what I mentioned in my original post above about finding a condition in the post-function, so hopefully someone has an idea of how that can be done :)

0 votes
Daniel Sabeti November 9, 2017

Anyone else have any thoughts on what the Condition would be? Should I create a ticket with Adaptavist?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events