Calulation for custom field
Asked by Kranthi Kumar:

Hello Team,  

We need this configuration for calculation for internal project.  

Imagine we have two text fields, A and B. Using automation, we calculate the sum of A and B and display the result in field C.  

If field A has value and B does not have any value, field C should still display the Field A result.  

How can I achieve this?  

thanks you


Answers:
author: Christopher Yen
body: Hi [@Kranthi Kumar](/t5/user/viewprofilepage/user-id/5029257)

I believe you would need an automation rule to fill out field C either on create or whenever the issue is updated.

You'll have to find the ID's for each custom field and then use the rule to fill out field C in the following format for the sum

{{#=}}{{issue.customfield_10000}} + {{issue.customfield_10001}}{{/}}

comments: author: Boris Zozoulia
body: consider using asNumber conversion if your fields are strings not numbers  

{{#=}}{{issue.customfield_10000.asNumber}} + {{issue.customfield_10001.asNumber}}{{/}}  

Also you can have a whole bunch of if else in your automation - to validate the presence of values in your custom fields, or utilise conditional logic in your smart values:

<https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/>


author: Kranthi Kumar
body: Hello [@Christopher Yen](/t5/user/viewprofilepage/user-id/5051689) [@Boris Zozoulia](/t5/user/viewprofilepage/user-id/4381887)   

Thank you for the response,

<br />

Following smart rules are functioning, but they require values in both fields to function.  

I'm concerned that field C should remain visible if any one of the fields contains a value  

how can I achieve?  

<br />


author: Boris Zozoulia
body: As I have mentioned before:
> Also, you can have a whole bunch of if else in your automation - to validate the presence of values in your custom fields, or utilise conditional logic in your smart value.

Take it back - the conditional logic in smart variables does not apply to setting fields, only send mail or comments though.

However try to use this

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

Where fieldA is your issue.customfiled_XXX and fieldB is your issue.customfield_YYY

Then you set your issue.customfield_ZZZ to use this smart value (represented in fieldC block above:

```
{{fieldA.asNumber.plus(fieldB.asNumber)}}
```

Jira Automation is using a moustache library under the hood, which is smart enough to behave like following tests:

1. fieldA = 1, fieldB = 2 then fieldC = 3

2. fieldA = 1, fieldB = {NULL or EMPTY} then fieldC = 1

3. fieldA = 1, fieldB = "some string" then fieldC = 1

4. fieldA = "some text", fieldB = "some more text" then fieldC = {EMPTY}

5. fieldA = {NULL or EMPTY} , fieldB = {NULL or EMPTY} , then fieldC = {EMPTY}

6. fieldA = 1, fieldB = {INVALID REFERENCE} then fieldC = 1

I believe the above is really what u are after.

Read the documentation mate:  
<https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/#Plus-Minus>  


author: Kranthi Kumar
body: Hello [@Boris Zozoulia](/t5/user/viewprofilepage/user-id/4381887)   

Thank you so much   

Now, I am good.  

Thanks again


Tags: cloud

jira-service-management

jira-service-management-cloud