Forums

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

Conditional Validator Alternative

John Wood
Contributor
July 14, 2020

Hi all,

 

I have a project where there are multiple workflows - I want to merge them into a single workflow as they are essentially the same except for a single thing, and currently I have to update them all each time there are changes.

 

On creation of an issue, there is a validator on one version that is:

 

Date Expression Compare (JSU)

  • Requested Window Start >= 3d
  • Including time part

 

This workflow is specific to an issue type, so what I am after is a way to say:

 

  • IF Issue Type is not Urgent
    • Requested Window Start >= 3d
    • Including time part
  • THEN
    • Do not allow creation
  • ELSE
    • Allow creation

 

I can see the argument for doing it as a condition, the trouble is that a condition can't be applied to create transition, and doing it at the next transition causes problems with issues that return to the start of the flow (ie it will no longer be 3 days).

 

We have these installed that might be relevant:

 

Jira Misc Workflow Extensions

JSU Automation Suite for Jira Workflows

Scriptrunner (though prefer not to do it via this, theres talk of it being removed

2 answers

1 accepted

1 vote
Answer accepted
David Fischer
Community Champion
July 14, 2020

You can indeed use JMWE's Scripted (Groovy) Validator together with JMWE's simplified API:

issue.getAsString("issuetype") == "Urgent" || issue.get("Requested Window Start") >= new Date() + 3

which means "issue is of issue type Urgent OR Requested Window Start is more than 3 days from now" which means that the validator will succeed if the issue is Urgent, or else if  its Requested Window Start is more than 3 days from now.

John Wood
Contributor
July 14, 2020

I'll test that shortly, thanks a lot

 

Just one question though, does that include the time part?

 

I could probably get away with it if it doesn't, but best if it does

 

edit: It does indeed, thanks

David Fischer
Community Champion
July 14, 2020

Yes, sorry, forgot to mention it. It does indeed.

John Wood
Contributor
July 21, 2020

Apologies for coming back to you and I hope you see this

 

If I want to do one based on time (so say "must be over X hours in future" instead of days, how does that work? I assume the date() needs changing, but I can't seem to find a list of acceptable...classes?

 

I did wonder about using 0.1666 of a day but I'm guessing that isnt the way!

David Fischer
Community Champion
July 21, 2020

To add something else than days to a date, you can use this:

use(groovy.time.TimeCategory) {
return issue.getAsString("issuetype") == "Urgent" || issue.get("Requested Window Start") >= new Date() + 5.hours
}
0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
July 14, 2020

I know JSU has "preconditions" implemented but it only works for postfunction so you can't use it. I didn't use JMWE for a long time but it looks like you can use scripted validators https://innovalog.atlassian.net/wiki/spaces/JMWE/pages/72089757/Use+cases+for+validators#[hardBreak]Scripted-(Groovy)-validator

I think it can be the best way for you to achieve your goal without scriptrunner.

Suggest an answer

Log in or Sign up to answer