Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Smart values: Greater or less than functions not working on (string).asNumber

FilBerry August 17, 2022

 

Hi,

Could you please help me here?
I want do something based on a greater than/ less than comparison of the "number" part of an issue key and another number: if(comparison) do something, but I can't get it to work.

I set up a simple rule to debug this: a manual trigger and the audit log action to see the result of the smart value.

I can extract the number part of the issue key just fine (using the example issue ABCD-857):
issue.key.split('-').get(1) --> 857

The result also seems to be numeric and of the correct length:
issue.key.split('-').get(1).isNumeric() --> true
issue.key.split('-').get(1).length() --> 3
issue.key.split('-').get(1).equals("857") --> true

But I somehow cannot compare it in a way to use it within a condition.
Although using the math tag it works...
#=issue.key.split('-').get(1) <= 100 / --> 0
#=issue.key.split('-').get(1) >= 100 / --> 1

...I can't find a way to combine the #if and the math tag, if that is possible at all.

So I tried to use lt/gt, but none of them gave me any output, also no error.
issue.key.split('-').get(1).lt(100) -->
issue.key.split('-').get(1).lt("100") -->
issue.key.split('-').get(1).asNumber.gt(100) -->
issue.key.split('-').get(1).asNumber().gt(100) -->

gt/lt seem to work as intended when I already have a number:

issue.key.split("-").get(1).length.gt(2) --> true

I suspect I messed up in the string to number conversion step, but I'm out of ideas, I'm sure I just made a stupid mistake and would appreciate any pointers here, thanks!

 

2 answers

1 accepted

0 votes
Answer accepted
FilBerry August 19, 2022

Our support managed to find a working solution using "number()" instead of asNumber():

{{#if (number(issue.key.split("-").get(1)).gt(900)) }} >900 {{/}}

{{#if (number(issue.key.split("-").get(1)).lt(900)) }} <900 {{/}}

1 vote
Radek Dostál
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.
August 17, 2022

This really seems wildly bugged.

Doing asNumber on the issuenum always returns null for me. Later on I checked that asNumber is only documented for cloud, but it is not documented for server - so fair enough, maybe it doesn't exist on server.

So I tried match() (https://confluence.atlassian.com/automation/jira-smart-values-text-fields-993924863.html#Jirasmartvaluestextfields-matchmatch()) which is documented for server, the matcher is java compliant, but no, it doesn't work for me either.

I wouldn't even be surprised if it was wrongly documented but didn't exist on server either, not sure why cloud/server editions of the same plugins have to vary so much when it's owned by Atlassian, but o well.

The only thing I can get to work is

{{#if(issue.key.split("-").last.equals("160"))}}
Equal to 160
{{/}}

which is hardly useful. Can't get either match() or asNumber to work - at this point I'd like to ticket atlassian if they can verify (at least the match) as a bug.

Radek Dostál
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.
August 17, 2022

Fair to assume you're doing this on the Create step? Maybe you could do this in the workflow rather than an automation rule, unless somebody else knows how to get it to work.

FilBerry August 18, 2022

Thanks for your insights!

I want to use this to correctly insert a newly created confluence page (for documentation and review purposes) into the page tree.

The ancestor id of the new page should be "switched" via smart value conditions, since it's a parameter of the HTTP POST payload.

Ideally I would have some if conditions (minimum 4 at the moment) to switch between the possible grouping page/ancestor, e.g. 2 of those would be groups by issue number, think (0-499, 500-999 etc.), one for the "currently active" group, one for the next, in case the issue numbers hit the 500.

In theory, I could put the conditions outside of the payload, directly in the rule, but I would have to quadrupel (is this a word?) the actual payload, which is (apart from being plain ugly) potentially a pain to maintain in the long run.

No local variables possible, too, for server.

FilBerry August 18, 2022

Do you by any chance currently have access to a cloud instance and could test isNumber there, too?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events