Subtraction does not work in jira automation
Asked by nasiruddin.nordin:

Hi all,

I have an automation to calculate as below :

{{#=}} {{issue.customfield_1299\|0}} + {{issue.customfield_1280\|0}}{{/}}

but the outcome always just show the result of customfield_1299 instead of actually adding or subtracting from customfield_1280.

When I tried like this : {{issue.customfield_1299\|0}} + {{issue.customfield_1280\|0}}

it will show something like this : 6 + 0

so customfield_1280 doesnt represent any value unfortunately. Can anyone help me on this please?


Answers:
author: Johnny Mon
body: Hi [@nasiruddin_nordin](https://community.atlassian.com/t5/user/viewprofilepage/user-id/5253928) ,

If we use the following, we will get an error instead of zero when both fields are EMPTY as noted in a similar community article [here](https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Maths-with-empty-fields/qaq-p/1002694):
>
> ```
> {{#=}}
> {{issue.customfield_13400}} + {{issue.customfield_13401}}
> {{/}} 
> ```

I think that's why you resort to using a "\|0" to avoid an EMPTY value:

```
{{#=}} {{issue.customfield_1299|0}} + {{issue.customfield_1280|0}}{{/}}
```

But I think the above may result in text values inside {{#=}}, and I don't know how A4J handles it. Thus, I think we got unexpected results.

Here my solution, using the[IF mathematical expression - IF(condition,value_if_true,value_if_false)](https://confluence.atlassian.com/display/AUTOMATION/Jira+smart+values+-+math+expressions) instead of using {{field\|0}}.
>
> ```
> {{#=}}
> {{IF(issue.customfield_13400,issue.customfield_13400,0)}}
> + {{IF(issue.customfield_13401,issue.customfield_13401,0)}}
> {{/}}
> ```

The above works, because the mathematical IF(,,0) always returns a true numeric zero.

Tests: {#toc-hId--408721234}
----------------------------

#### Setup (validate using issue NSP-25 custom fields 13400 and 13401) {#toc-hId--1515111119}

![test-web-request-validate-issue.png](https://community.atlassian.com/t5/image/serverpage/image-id/298144i102D089771A2B126/image-size/large?v=v2&px=999 "test-web-request-validate-issue.png")

#### A + B {#toc-hId-972401714}

![a.plus.b.png](https://community.atlassian.com/t5/image/serverpage/image-id/298146i9440AC623AA3C7D5/image-size/large?v=v2&px=999 "a.plus.b.png")

#### A + B (empty) {#toc-hId--835052749}

![a.plus.empty.png](https://community.atlassian.com/t5/image/serverpage/image-id/298147iC09C0B240DE1BDAD/image-size/large?v=v2&px=999 "a.plus.empty.png")

#### A (empty) + B {#toc-hId-1652460084}

![empty.plus.B.png](https://community.atlassian.com/t5/image/serverpage/image-id/298148i35C44EE3A25BB992/image-size/large?v=v2&px=999 "empty.plus.B.png")

#### A (empty) + B (empty) {#toc-hId--154994379}

![empty.plus.empty.png](https://community.atlassian.com/t5/image/serverpage/image-id/298143iAEE6CEECD9E93F7F/image-size/large?v=v2&px=999 "empty.plus.empty.png")


author: Bill Sheboy
body: Hi [@nasiruddin.nordin](/t5/user/viewprofilepage/user-id/5253928)

Context is important for automation rule questions. Please post an image of your complete automation rule, images of any relevant actions / conditions / branches, an image of the audit log details showing the rule execution, and explain what is not working as expected. Those will provide context for the community to offer ideas. Thanks!

Until we see those...

You note both fields are number types. Have you confirmed that?

Have you confirmed the custom field id values you are using? For example, by writing those individual smart values to the audit log to confirm they contain what you expected?

Kind regards,  
Bill


author: Mohammed Aamer Khan
body: Hi [@nasiruddin.nordin](/t5/user/viewprofilepage/user-id/5253928)  

Try using below smart values for addition  
{{#=}} {{issue.customfield_1299.plus(issue.customfield_1280)}}{{/}}


author: nasiruddin.nordin
body: I have tried to do like this as well :

{{issue.customfield_10299}} + {{issue.customfield_10280}}

![Image 21-12-2023 at 12.57 PM.jpeg](https://community.atlassian.com/t5/image/serverpage/image-id/297690i2758E05213C49B9D/image-size/large?v=v2&px=999 "Image 21-12-2023 at 12.57 PM.jpeg")

and the result i got was 4.0+

It does not detect the customfield_10280.

I have checked the type of everyfield and it is number fields so by right it should work :(


Tags: cloud

jira-software

jira-software-cloud