For my company, I have set up a Service Management HR project for employees to request holidays, time off in lieu etc.
This then clones the request into a Holidays Software project which has an epic for their allowance using original estimate & remaining estimates for how much holiday they are entitled to and how many days they have left.
It then adds a story under that epic for each request they put in with the start and end date.
They can then view this on an Advanced Roadmaps For Jira Plan to use as a holidays calendar and pull those Stories into their own plans so they know who's on holiday when planning work.
On the request form, I need the employee to fill out a duration field for how much time off they'd like, which could be 1d, 1h or even 30m etc, so I need them to specify.
This is then used to log time again their holiday epic using the Jira Cloud API to reduce their remaining estimate field.
The problem is I have to monitor each request to make sure they put their duration in the correct format that Jira likes. e.g. 1w 5d 2h 30m with a space separating each time unit. If they don't put a space Jira doesn't like it.
So I want to add a validator on the "Create" transition of the workflow which uses a regex to check for the correct format, I think I'm almost there with the below regex but if anyone has done this before or has any ideas then please let me know!
I'm basically struggling to get the whitespace check to not match when there's no whitespace between 1d5h or 5h30m.
\s+ - is looking for 1 or more spaces
s* - is looking for 0 or more spaces
Obviously, there's only ever whitespace when another time unit is added so just 1d would still need to pass the check with no whitespace.
I may have gone down a rabbit hole trying to figure this out, and there could be an easy solution that I've missed, any help is appreciated.
Bummer that there isn't a "duration" type for a custom field.
Be sure to cast a vote here for such a feature to be added to Jira.
As for your regex, keep in mind that Jira is typically happy with things like "4.5h" for a duration also, not just whole values for each time unit. Obviously this complicates the regex even more. But your users may be used to that.
If you are intent on a regex, then let me offer a couple of things:
^ *([0-9]+[WwDdHhMm] *)+$
Note that it is very forgiving about space characters (no need to worry about other whitespace). Decimals are not incorporated. It does not accept a number without a letter. So this is not a direct replacement for Jira built-in duration fields. I offer it as a starting point.
Adding decimals might look like this, but it doesn't support something like ".5d" yet:
^ *([0-9]+(.[0-9]+)*[dDwWmMhH] *)+$
Let us know here what you ended up with!
Thanks for your reply :D
Also thank you for the issue link for the duration field, I have voted and now I'm watching it too. I really hope we get that soon!
Sadly I need to enforce that spaces are used because once their holiday is approved, I have a script runner script that takes the holiday duration value and passes it through to the holiday's board and also uses that value to log time to bring down their remaining time on their holiday epic.
When I pass "4d1h" for example with no spaces via Scriptrunner, the value isn't handled properly, off the top of my head I think it would log 4d and ignore the 1h.
That's why I originally went for the capture group route.
Sadly I've not had time to revisit this regex yet so I'm just manually checking each holiday request before it's approved and changing the spacing or format if I need to.
If I get round to sorting it, I'll definitely update this thread.
To enforce spaces between values, you can use this regex:
^ *([0-9]+[WwDdHhMm])( +[0-9]+[WwDdHhMm])* *$
For those playing along at home, here's how to decode this:
All my years as a unix developer really helped develop my "regex fu". :-)
Here's the next iteration:
This allows decimal points and only a single space between elements, and no spaces at the beginning or end.
Additional tweaks will be left as an exercise for the reader.
Amazing! Thank you so much @Mykenna Cepek I really appreciate your help and skills with this. 🙌
This is the final version I have implemented as a workflow validator on the create transition (just ensured letters were lowercase):
@Adam Wood another solution you might find helpful is ProForma Forms for Jira. Full disclosure I’m one of the Product Managers of ProForma and we recently joined Atlassian team; however, you can use ProForma to build dynamic forms which you can publish on your JSM portal. There are also a greater number of field validation options than normal JSM, including Regex. This means you can apply the regex check when the team member is attempting to create the issue, rather than once it has been created.
Just a thought.
Kudos to @Mykenna Cepek for your regex pattern too.
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event