Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

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



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) -->
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) --> 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

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

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() ( 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

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.

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.

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.

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
Community showcase
Published in Confluence

Watch 4 Confluence apps compete for Best App Demo in September's Appy Hours

Calling all collaborators! Appy Hours on the Atlassian Community is a monthly event where 4 Partner and app vendor presenters go head-to-head with 5-minute demos for the title of Best App Demo. I...

524 views 0 12
Read article

Atlassian Community Events