Forums

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

Calulation for custom field

Kranthi Kumar July 31, 2024

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

1 answer

0 votes
Christopher Yen
Community Champion
July 31, 2024

Hi @Kranthi Kumar 

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}}{{/}}

Boris Zozoulia
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.
July 31, 2024

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/

Like Christopher Yen likes this
Kranthi Kumar July 31, 2024

Hello @Christopher Yen  @Boris Zozoulia 

Thank you for the response,


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?


Boris Zozoulia
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.
August 1, 2024

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

 

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

Kranthi Kumar August 1, 2024

Hello @Boris Zozoulia 

Thank you so much 

Now, I am good.

Thanks again 

Suggest an answer

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

Atlassian Community Events