Smart value for text to number using asNumber does not work

Zhengguan Li November 11, 2023

I have defined a rule to draft next release by incrementing the patching number by 1, the smart value I use is the following. I tested by releasing "test: 0.0.1", however it generate "test: 0.0.". Looks like asNumber does not work for me...

{{version.name.substringAfterLast(".").asNumber.plus(1)}}

3 answers

1 vote
Bill Sheboy
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.
November 11, 2023

Hi @Zhengguan Li -- Welcome to the Atlassian Community!

Please try using the straight versus the curly quotation marks to help that expression parse correctly:

{{version.name.substringAfterLast(".").asNumber.plus(1)}}

If that does not work, I suggest building your expression piece by piece until it fails.  That will explain the problem.  For example, first write just the version name to the log.  Then add the substring function, and so on.

Kind regards,
Bill

Zhengguan Li November 11, 2023

I am using straight, when I pasted it, somehow it changed, I tried to build piece by piece, it can only work till asNumber

image.png

Zhengguan Li November 11, 2023

It can get 1, but the rest are empty

Bill Sheboy
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.
November 12, 2023

Would you please clarify how you want to increment the version number?  That will help the community to make better suggestions to help.  Thanks!

For example...

You initially described wanting to increment the version name "test 0.0.1".  And it appears you want to increment only the last digit to 2, leading to a new version of "test 0.0.2".

To do that, please try splitting the value into the two parts: value before the last digit and the last digit...and then concatenating the results.  That would be this:

{{version.name.substringBeforeLast(".").concat(".")}}{{version.name.substringAfterLast(".").asNumber.plus(1)}}

Please note this handles only the case of incrementing the last digit after the final period, does not handle errors, and cannot increment the other digits.

Also note: the smart value expression I show appears to be on two lines, but it is not.  That is just the text wrapping in the community posts.

Zhengguan Li November 12, 2023

Yes, you are right, if the current version "test: 0.0.1", the new version will be "test: 0.0.2", then "test: 0.0.3"...I am using expression: 

{{version.name.substringBeforeLast(".")}}.{{version.name.substringAfterLast(".").asNumber.plus(1)}}
Zhengguan Li November 12, 2023

I tried your solution, still not working..

image.pngimage.png

Bill Sheboy
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.
November 12, 2023

Please add a write to the audit log, after the trigger, with this expression.  It may indicate why the value is not working as expected:

version from trigger: !!{{version.name}}!!

This will show if there are extra characters in that name which are preventing the parsing or the conversion.  If that does not help...

 

Another possible cause to this not working is rules can become broken due to several edit / publish cycles.  This can happen due to some apparent problem in the rule editor. 

The way to check for that is:

  1. Disable the rule, wait a minute, re-enable the rule, and then re-test.  If that does not help...
  2. Disable the rule, and re-create the rule as a new one with the same steps.  Then test that rule.
Zhengguan Li November 12, 2023

It never works..but I can try disable and enable rules...

This is what I have after adding write to audit log...I guess it just does not work...

image.png

Bill Sheboy
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.
November 13, 2023

I believe the problem is using multiple smart value expressions in the Create Version action's name field.  I just tested and this works:

  • use the Create Variable action to create the new version name
    • name: varNewVersionName
    • smart value: the expression we created earlier
  • in the Create Version action, use {{varNewVersionName}} as the name
Zhengguan Li November 13, 2023

Does not work...image.pngimage.png

Bill Sheboy
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.
November 13, 2023

Would you please post an image of your Create Variable action? 

Based on what your log is showing, that can be the only place remaining to explain this behavior.  When I tested with exactly the same version name and smart value expression, this worked for me with Jira Cloud's version of automation rules.

 

I saw you also posted "forget about it for now", so please disregard my request if you want to drop this one.  Thanks!

0 votes
Zhengguan Li November 13, 2023

I guess it just does not work, it would say forget about it for now...

0 votes
Murat Seven
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.
November 11, 2023

Hi @Zhengguan Li  and Welcome to the Atlassian Community!

Screen Shot 2023-11-11 at 3.20.50 PM.png

 

I tested it, and I'm getting success in automation. Can you provide more information and screenshots related to automation? 

Zhengguan Li November 11, 2023

Thanks for quick reply, I attached the screenshot in Bill's thread

Murat Seven
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.
November 12, 2023

Hi @Zhengguan Li and thanks for your screenshot.  

 

can you try this smart value please?

{{version.name.substringBeforeLast(".")}}.{{version.name.substringAfterLast(".").asNumber.plus(1)}}

Best,

Murat Seven

Like Bill Sheboy likes this
Zhengguan Li November 12, 2023

This is exactly what have, I did not post initially because I think the problem was the latter expression. The last part result is always nothing. I also tried @Bill Sheboy solution using `concat`, but no luck...

Zhengguan Li November 12, 2023

This is the screenshot:image.pngimage.png

Murat Seven
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.
November 12, 2023

Hi @Zhengguan Li 

I don't see any errors in your expression for "smart value," but there might be a syntax issue. I have two requests:

First, could you try the following smart value with the log action and share the result?

{{version.name.substringAfterLast(".").asNumber}}

Also, could you disable this automation, create a new one, and try it again? Please make sure to recreate the smart value without any spaces between its components.

Zhengguan Li November 13, 2023

I don't have space, just the format make it looks like it has. I have tried the troubleshoot blow previously, it can only get current version, but not the rest..

image.png

Michael Andrus
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 28, 2024

@zhen I don't know if you are still struggling with this, but I experienced a similar issue, where my smart value variables were returning empty when using asNumber (without returning an error in the audit log).

I discovered that asNumber is not supported by my Jira Software product version (Datacenter). This function appears to only be supported by Jira Software Cloud. My final solution was similar, but I used math expressions found here instead of asNumber: https://confluence.atlassian.com/automation/examples-of-using-math-expression-smart-values-993924632.html.

I hope this helps save someone time in the future.

Thanks!

Suggest an answer

Log in or Sign up to answer