I have a field for estimations, "T-shirt size", where the developers can estimate the amount of work before they actually start. This is a text field, with these options right now:
As a goal, I want to extract the larger numeric value for each entry and use that for later calculation in automation rules.
I found several substring-functions and started testing with them to figure out how to parse the string, but so far these returns nothing for me :(
I have a manually triggered test rule that simply logs output for now:
Now, running this on a subtask with T-shirt size field set to "M (3-5)" I get this output in audit log:
What am I doing wrong?
I'm running a Team-managed Jira software project in Cloud
As final result, I want to extract the "5" and convert it to a number, but neither of my substring seems to do anything useful.
Aw c'mon guys, a bunch of IF-ELSE statements isn't any fun!
I think @Niklas Malmberg the problem is that you should be using:
{{issue.t-shirt size.value}}
I don't know if Atlassian ever documented the value thing. There's a bit about it buried here:
https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/
(Oh neat, @Fabian Lim made a video about it this.)
It seems that what you really want is the last number before the closing parentheses. So you can use the match() operator for that.
So what you could do is:
{{issue.t-shirt size.value.match("\D+(\d+)\)")}}
That's a regular expression, and what it means is:
\D = a non-digit character
+ = at least one or more of the previous characters
\d = a digit-character
+ = again, at least one or more of the previous characters
The digits are "captured" in parentheses: (\d+)
And lastly, the key is that we're looking for that closing parentheses in the select value, which we have to escape with a backslash, so \)
An incredible tool for better explaining regular expressions and TESTING them is regex101.com, and I've saved the one above for you to check out:
Here's of a screenshot of the rule in action. Or well, logs of it:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Darryl Lee - Awesome response, and quite elegant in the use of complex operators in the automation. I prefer to keep things more readable (as I do with my programming too). It may be more verbose or a few extra "lines of code", but I find it easier to debug 😂
Always love seeing the more complex and elegant things though!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Now we're talking !
1. Yes,
.value was the lacking part. Now my substring functions return something, and logical too.
The original example above with input "M (3-5)" yielded these outputs:
Makes complete sense.
2. To use RegExps instead did not even enter my mind, but it's elegant and a much better solution than mucking with substrings. Excellent, Sir!
3.
Yes, I agree with Jovin too, that the resulting rule might not be very easily readable (I miss the possibility of adding comments anywhere I want in a Jira automation rule).
Still, the rule description field is available, and most rules are after all quite short.
Thank you @Darryl Lee !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
BTW, the RegExp suggested did not handle the string "XS (0,5)" properly.
It's a rather local standard to express decimal numbers with a comma, I know a point/dot separator is more common.
But anyhow, a non-digit character made the RegExp "\D+ (\d+)\)" return wrong, 5 instead of 0,5
I played around on regext101.com and landed in regExp "([0-9.]+)\)", and using decimal dot in all my strings like "XS (0.5)"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh! I totally missed that you were using fractional points!
So yeah, I think you could keep using a comma, if you used:
([0-9,]+)\)
Confirmed in regex101 that this works: https://regex101.com/r/1L6pBV/1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It feels like you're making this more complex than it needs to be.
For example, why does it need to be a text field? Why not a select list or a number field to make this simpler?
Ste
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This field is not really mine to edit, it's used by several projects at the company. And since it's call T-shirt size, The XS, S, M, L-notation is rather expected.
But how come the substring functions all returns nothing?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure, but just want to ensure they're necessary.
Is it that you will take whatever number is after the "-" each time? Or, you just want the biggest number every time? EG. for small you always want 2?
Could you also clarify what you'll use the numbers for?
Ste
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The question is really:
For a string like "M (3-5)" residing in a field called 't-shirt size' on a Jira issue, how can I extract the last numerical character(s), so I can convert that to a numerical value later on?
According to the documentation, given input "M (3-5)", the function {{ issue.t-shirt size.substringBetween("-",")") }} ought to return the string "5", but for some reason it doesn't.
Does anyone know how the parsing should be written to accomplish that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The reason I'm asking is IF/ELSE statements could be easier here - i.e
---
For the smart values though, I tested this in a test environment and it works fine for me.
One thing you could try is using the exact field name, including the capitalisation of "T-Shirt Size". This can be an issue sometimes!
Ste
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Niklas,
For simplicity have you tried adding an "IF ELSE" condition and simply iterating over the options? Meanwhile this is less "dynamic" it's guaranteed to work unless you change the options :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jovin , sure I will need to add conditions, but for now I started simple - I just want to figure out how to parse a string and extract a part that I later could turn into a number.
So my test is just this, first displaying the string to audit log and then try to use several ways to look into subparts of the string value.
As you can see, I'm 1) searching for the divider - between number chars, 2) searching for the ending paranthesis, and also 3) trying to look for both.
Unless I can find any number in the string, subsequent IF-ELSE will not do much.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Niklas Malmberg,
I can see that the T-Shirt size is a select list, in that case you simply need to make the IF statement be comparing the "Issue Field", like the screenshot below, simply replace Change reason with your T-shirt size and for each of the IF/ELSE/ELSE/ELSE choose a different option.
By using this method you don't need to use substrings at all.
Following the condition, you can then do an Action to "Edit Issue" with the field desired to capture the scoring you've got.
e.g.
IF "T-shirt size" EQUALS "Small (0,5)"
EDIT ISSUE FIELD "Story Points" with value 0,5
ELSE IF ....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, that might work, will try that for sure.
Just annoyed that my substring*-calls are just not working at all :/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Right, that worked.
I had to add a block of ELSE IF for each possible value, like
so it's not elegant but it did it's work just fine.
Thanks @Jovin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Amazing! I sometimes get caught in a cycle of making things more complex too, community is an amazing resource for sense-checking and simplifying and I'm glad I could be a part of that journey!
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.