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

How to validate non empty number fields in automation with regular expressions

Mario Benedí Plana June 9, 2022

Hi team,

We have some automations which are calculating the costs or time of the projects depending on the rate (customfield_10181), actually we have this expressions to calculate it:

To the costs we multiply the hours with the rate and to the opposite we divide it:

Examples:

{{#=}}{{issue.ENE21 Plan H}} * {{issue.customfield_10181}}{{/}}

{{#=}}{{issue.FEB21 Plan H}} * {{issue.customfield_10181}}{{/}}

{{#=}}{{issue.MAR21 Plan H}} * {{issue.customfield_10181}}{{/}}

...

{{#=}}{{issue.ENE21 Plan €}} / {{issue.customfield_10181}}{{/}}

{{#=}}{{issue.FEB21 Plan €}} / {{issue.customfield_10181}}{{/}}

{{#=}}{{issue.MAR21 Plan €}} / {{issue.customfield_10181}}{{/}}

 

This are working fine but there are showing errors if the users are deleting the values and putting some number field on null, we tried to use some expressions to controlling it but it doen't work fine either, I think it can be something like this:

 

{{#=}}{{IF(issue.ENE21 Plan H == null, 0, issue.ENE21 Plan H)}} * {{issue.customfield_10181}}{{/}}
{{#=}}{{IF(issue.FEB21 Plan H == null, 0, issue.FEB21 Plan H)}} * {{issue.customfield_10181}}{{/}}
{{#=}}{{IF(issue.MAR21 Plan H == null, 0, issue.MAR21 Plan H)}} * {{issue.customfield_10181}}{{/}}
{{#=}}{{IF(issue.ABR21 Plan H == null, 0, issue.ABR21 Plan H)}} * {{issue.customfield_10181}}{{/}}

...

{{#=}}{{IF(issue.ENE21 Plan € == null, 0, issue.ENE21 Plan €)}} / {{issue.customfield_10181}}{{/}}
{{#=}}{{IF(issue.FEB21 Plan € == null, 0, issue.FEB21 Plan €)}} / {{issue.customfield_10181}}{{/}}
{{#=}}{{IF(issue.MAR21 Plan € == null, 0, issue.MAR21 Plan €)}} / {{issue.customfield_10181}}{{/}}

 

If someone knows how to solve it, it would be very helpfull to our team.

Thanks in advance,

Mario

2 answers

0 votes
Simmo
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 14, 2022

Hi @Mario Benedí Plana

You can add default values to your smart values to catch a missing value and stop the expressions breaking. Just add |0 to it. For example:

{{issue.customfield_10181|0}}

Will default to 0 if there is no value.

Hopefully that helps.

Cheers,

Simeon.

0 votes
Fernando Eugênio da Silva
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 9, 2022

Mario,

In fact, if the field is of type number field, leaving the value empty or null will cause automation errors or the final result to appear incorrect.

Instead, try to instruct your users to use the number 0 or 1 and not leave the number field empty.

I think this will be enough to help you.

If this doesn't work or it's not interesting to apply, please let me know. We can try other ways.

Mario Benedí Plana June 13, 2022

Hi Fernando,

 

thanks for the quick response :)

We already put warning messages in the forms to prevent the users deleting values saying they must put 0 values, but sometimes they don't do it well and delete it anyway.

For prevent that errors we want to control it with some expression.

 

Also we think when the Scriptrunner Behaviours are able in cloud it could solve this right?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events