Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Automation - handling empty fields on static rule

Ron Aisen
Contributor
December 19, 2024 edited

Hi,

I've created a jira automation that creates a table in the description field based on custom fields I added to the form, and I'm also calculating the sum of all items i.e if I have an order for 10 devices it will calculate each device type unit * price per table row and in the bottom of the table will post the total of all devices:

Screenshot 2024-12-19 at 13.28.41.png

 

Here is the automation rule:

||*Needed Device*||*Quantity*||*Cost Summary*|| |{{issue.Needed Mobile Device New}}|

{{issue.Quantity New}}|{{#=}}{{issue.Needed Mobile Device New.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New}}{{/}}| |

{{issue.Needed Mobile Device New 2}}|{{issue.Quantity New 2}}|{{#=}}{{issue.Needed Mobile Device New 2.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 2}}{{/}}|

|{{issue.Needed Mobile Device New 3}}|{{issue.Quantity New 3}}|{{#=}}{{issue.Needed Mobile Device New 3.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 3}}{{/}}|

|{{issue.Needed Mobile Device New 4}}|{{issue.Quantity New 4}}|{{#=}}{{issue.Needed Mobile Device New 4.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 4}}{{/}}|

|{{issue.Needed Mobile Device New 5}}|{{issue.Quantity New 5}}|{{#=}}{{issue.Needed Mobile Device New 5.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 5}}{{/}}|

|{{issue.Needed Mobile Device New 6}}|{{issue.Quantity New 6}}|{{#=}}{{issue.Needed Mobile Device New 6.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 6}}{{/}}|

|{{issue.Needed Mobile Device New 7}}|{{issue.Quantity New 7}}|{{#=}}{{issue.Needed Mobile Device New 7.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 7}}{{/}}|

|{{issue.Needed Mobile Device New 8}}|{{issue.Quantity New 8}}|{{#=}}{{issue.Needed Mobile Device New 8.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 8}}{{/}}|

|{{issue.Needed Mobile Device New 9}}|{{issue.Quantity New 9}}|{{#=}}{{issue.Needed Mobile Device New 9.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 9}}{{/}}|

|{{issue.Needed Mobile Device New 10}}|{{issue.Quantity New 10}}|{{#=}}{{issue.Needed Mobile Device New 10.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 10}}{{/}}|

Total = ${{#=}}({{issue.Needed Mobile Device New 2.getValue().substringAfter("$")}} * {{issue.Quantity New 2}}) + ({{issue.Needed Mobile Device New 2.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 2}}) + ({{issue.Needed Mobile Device New 3.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 3}}) + ({{issue.Needed Mobile Device New 4.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 4}}) + ({{issue.Needed Mobile Device New 5.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 5}}) + ({{issue.Needed Mobile Device New 6.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 6}}) + ({{issue.Needed Mobile Device New 7.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 7}}) + ({{issue.Needed Mobile Device New 8.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 8}}) + ({{issue.Needed Mobile Device New 9.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 9}}) + ({{issue.Needed Mobile Device New 10.getValue().substringAfter("$").remove(",")}} * {{issue.Quantity New 10}}){{/}}

 

Problem is that this handles full 10 fields per each device, so if for example I'm only ordering one or two devices I get an error for the '*'  operand that the automation can't resolve it, any suggestions on how to solve it without creating massive if blocks per each situation?

2 answers

0 votes
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.
December 19, 2024

Hi @Ron Aisen 

What do you want to do when a quantity value is 0 or empty:

  1. do not display that row in the table
  2. display the row with a 0 Quantity and Cost Summary
  3. something else

Kind regards,
Bill

Ron Aisen
Contributor
December 19, 2024

it's a mix of 1 and 2, basically don't create a row if the field is 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.
December 19, 2024

I am unclear how to mix those options as they seem mutually exclusive...

To prevent display of a row with a 0 quantity, wrap each row with a conditional, smart value expression to test for a 0 or empty quantity: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/

To display all rows, with 0 when relevant, use either 0 prefix value or default value, as @Manon Soubies-Camy described.  Please note well: that syntax does not work for all possible field types, and I recommend testing to confirm for your fields.

Like • Manon Soubies-Camy likes this
0 votes
Manon Soubies-Camy
Community Champion
December 19, 2024

Hi @Ron Aisen,

You can use | to provide automation rules with default values if your field is empty, for example:

{{#=}}{{issue.story points|1}} * 5{{/}}

If the Story points field is empty, then it'll be replaced with value 1.

Hope this helps!

- Manon

Ron Aisen
Contributor
December 19, 2024

Thanks Manon, it didn't answer my need but I appreciate the help

I ended up doing if blocks saddly but it works so that's what counts

Like • Manon Soubies-Camy likes this

Suggest an answer

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

Atlassian Community Events