Adding 2 custom fields together not working?
Asked by Ethan Bhardwaj:

I've been trying to get 2 custom fields to be added together and comment the outcome in the comment section of the form. This is working when Customfield + 3.95 the output is adding them together and then commenting the correct output. However, we are trying to make the "3.95" a customer field that can be changed depending on what options are selected in the form, So we have changed the code the represent this with a custom field + custom field the outcome is being commented is just the input from the first custom field and the math s not being applied.

This code is working:  
![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338131iA22AA2FCD2A9DC67/image-size/large?v=v2&px=999 "image.png")

This code is not working

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

(Please note we have tried adding both custom fields with Issue.customfieldname and with the custom field ID and both are not added together correctly.

Further note:   
here is the audit log of the automation, it shows as successful and that the equation is commented as written.![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338169i31DE088825A65335/image-size/large?v=v2&px=999 "image.png")


Answers:
author: Bill Sheboy
body: Hi [@Ethan Bhardwaj](/t5/user/viewprofilepage/user-id/5553391) -- Welcome to the Atlassian Community!

In addition to the other suggestions offered...

I note your rule is editing an issue field before the attempt to add the comment. *Is the comment referencing the field just edited and was that field empty before the edit?*

If so, your rule is missing an action to Re-fetch the issue after the edit and before the comment:

* ...
* action: Edit Issue field
* **action: Re-fetch Issue**
* action: Add comment
* ...

When a rule edits an issue, it is updating the data in the Cloud storage and is not updating the data as the rule proceeds. To refresh the data to the current state, add the Re-fetch Issue action to reload the issue before the rule proceeds.

Kind regards,  
Bill


author: Tim Kopperud
body: Hi [@Ethan Bhardwaj](/t5/user/viewprofilepage/user-id/5553391), welcome to Atlassian community.

~~Are you able to provide images of~~

1. ~~the math formula,~~
2. ~~the two field values used. That means from an issue where the two fields contain values, but are not working?~~

**Edited**: I noticed later editions of the original question included this.

TimK

comments: author: Tim Kopperud
body: [@Ethan Bhardwaj](/t5/user/viewprofilepage/user-id/5553391), try small letters. **customfield_xxxxx**, not customField_xxxxx.

TimK.


author: Ethan Bhardwaj
body: Hi Tim,   

thanks for the swift reply,   

Currently, we have an automation that takes the "remaining balance" from an input field in the form and sets it to a custom number field ![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338133i27C0111B6AFCBE06/image-size/large?v=v2&px=999 "image.png")  
We then have another automation that has an If statement so depending on the input selected it will set the second field in this case "fee" to the appropriate number ![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338134iE1B180551F5B3020/image-size/large?v=v2&px=999 "image.png")  
We then have an automation that will add these custom fields together to comment on the final balance but this is where it is not working.  

I hope this information can help.  

Ethan


author: Ethan Bhardwaj
body: Hi [@Tim Kopperud](/t5/user/viewprofilepage/user-id/492874) ,

Unfortunately, the change in capitalisation hasn't affected the result.

Ethan


author: Tim Kopperud
body: Hi [@Ethan Bhardwaj](/t5/user/viewprofilepage/user-id/5553391), can you provide the two things I mentioned in my first reply, now over-striked? Including the newly edited formula where you are using small caps.

Also provide the result, i.e. the comment added.

TimK


author: Ethan Bhardwaj
body: Hi [@Tim Kopperud](/t5/user/viewprofilepage/user-id/492874)  

no problem, here is the code for commenting an outcome.![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338143iE5528DFC46A69F62/image-size/large?v=v2&px=999 "image.png")  

The bottom comment happens first this displays the 1st custom field in this case the remaining balance that is inputted in the form. the top comment is supposed to show the 1st custom field + the 2nd custom field which in this case is fee and then comment the result. As you can see it is not adding the field. this field is being set in a radial field   
![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338145iF2E1C288F1986AC4/image-size/large?v=v2&px=999 "image.png")  

<br />


author: Tim Kopperud
body: [@Ethan Bhardwaj](/t5/user/viewprofilepage/user-id/5553391), since it seems you are using this rule for testing, I might recommend another approach for error investigation on smartvalues:

1. Make the rule as simple as possible  

2. Use manual rule triggers, e.g. scheduled with a random long time span, using a selected issue like I have done below using issue MOBL-28.   
   ![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338328i0BC3755F81F21E90/image-size/large?v=v2&px=999 "image.png")  
   Execute this rule manually during investigation:  
   ![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338326i4A357EF3FE997032/image-size/large?v=v2&px=999 "image.png")  
   ..and disable or delete the rule when investigation is over.  

3. Dump everything to the audit log only, using **Log action**.

I have created an example rule for trying to reproduce the error:

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

Mapping of CFs are:  
16034 =\> 10215 Remaining fee   
16133 =\> 10216 Activation fee

This created the following in the log entry when I executed it manually (no errors):

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

This way we can see where the log actions (LAx) first hit an error. E.g. in your case you can see if its about fetching the value (in LA2) or if it is the formula (in LA3) etc.

Can you try something like this, and post the result?

TimK


author: Ethan Bhardwaj
body: Hi [@Tim Kopperud](/t5/user/viewprofilepage/user-id/492874) ,   

Thank you for your response, ![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338597iA7576F3FF5125525/image-size/large?v=v2&px=999 "image.png")

As you can see from the tests, the Activation fee is not being set correctly.

The fee is set from a Radio button selection

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338598i83AF45D84E194F6C/image-size/large?v=v2&px=999 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338599iAFC985BC989B661B/image-size/large?v=v2&px=999 "image.png")

This Automation sets the radio button selection and adds the relevant fee to the custom field then additional automation then on issue creation comments the sums   

As you can see from the XML of the issue raised, the value of the fee has been set to 2.95

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

I hope this Log helps  

- Ethan


author: Tim Kopperud
body: Hi [@Ethan Bhardwaj](/t5/user/viewprofilepage/user-id/5553391) , try using {{customfield_10037.value}}

TimK


author: Tim Kopperud
body: Hi [@Ethan Bhardwaj](/t5/user/viewprofilepage/user-id/5553391), sorry for my short reply yesterday, I was "PC offline", hence was not able to test accordingly, and replied from mobile. After testing it seems it works without using ".value" syntax.

I do agree with [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) and [@Dick](/t5/user/viewprofilepage/user-id/4586768) that refetching the issue is important when you, within the rule, edit a field value and attempt to use that newly set value later in the same rule.

But when you post this image

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

I understand you have created a test rule as recommended earlier which is triggered manually and is as simple as possible with no edit or filter, hence you haven't actually edited the issue within the rule when doing this test.**Is this correct?**

The red line above is where we expect to find a number.

The next image you attached doesn't show this test rule as I cannot see any "Log actions" in it.

Can you provide an image of the test rule where ypu are setting the log actions? Most important to include is the Log action for LA1 (red line above).

TimK


author: Ethan Bhardwaj
body: Good Morning [@Tim Kopperud](/t5/user/viewprofilepage/user-id/492874)

Thanks for your continued help is appreciated.

Attached is the test automation yet sent to me, I switched it to when a form is created. Both values of the custom fields are defined when the form is filled out, as both the remaining balance and fee need to be entered here. So in this case, as you can see in the XML code the "Activation fee" field is being defined as I have tested with other numbers and the XML reflects this change. I hope this all makes sense.

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

If you have a solution or a fix I would be grateful.

-Ethan


author: Tim Kopperud
body: Hi [@Ethan Bhardwaj](/t5/user/viewprofilepage/user-id/5553391), I don't have the solution yet, but we might get there soon.

Can you, in the test rule (your image above) switch the rule trigger (green step) and replace it with **Scheduled** trigger? You can replace it by simply delete the existing trigger and add a new one.

In that scheduled trigger:

* set the JQL to **issue = \<issuekey\>**. Replace \<issuekey\> with an example issue key where you know the customfield_10037 contains a value.
* The checkbox "Only include issues...." must be unchecked.

See my previous image (with all those yellow markings) as an example hwr to configure the scheduled trigger.

**Execute the rule manually**.

If the audit log still doesn't show any value for LA1 please attach images of:

1. The new schedule trigger.
2. The issue itself where you have the value set and is the same as set in the manual schedule JQL. (Remember to blackout any confidencial information).
3. The auditlog result.

TimK


author: Ethan Bhardwaj
body: Hi [@Tim Kopperud](/t5/user/viewprofilepage/user-id/492874)

I got the following error when entering the scheduled command you posted above.

I tried both the custom field ID and the name of the custom field itself and have received errors both times.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338854iEEA5B3466A95D709/image-dimensions/635x82?v=v2 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338855i7C1807457BC1916E/image-dimensions/356x384?v=v2 "image.png")

This is where the issue is being applied in a separate automation the fee is being applied like this, I have added a log action to this automation to check to see if the problem lies here but as you can see from the attached audit log it is being updated correctly, for some reason, this is not being updated when the other automation is trying to add and comment them to the raised form.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338857i9981A579610DD122/image-dimensions/394x363?v=v2 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338858i1F458D3F0024BB42/image-dimensions/409x376?v=v2 "image.png")

- Ethan


author: Tim Kopperud
body: Hi [@Ethan Bhardwaj](/t5/user/viewprofilepage/user-id/5553391), the JQL should be

```
issue = CS-10
```

By your last image CS-10 seems to be the issue you are testing against, hense this is what we apply to the JQL.

Try this, and test according to my previous reply.

TimK

Answering from mobile.


author: Bill Sheboy
body: One more thing about the Re-fetch Issue action...

When using the Issue Created trigger, that one can fire so quickly that some of the issue data may not yet be available to the rule. This will cause symptoms like empty fields and rule steps not working as expected, possibly even errors in the log.

The fix for this is to **always add the Re-fetch Issue action immediately after the Issue Created trigger**. This will slow down the rule a bit, reloading the data before the rule continues.


author: Ethan Bhardwaj
body: Hi [@Tim Kopperud](/t5/user/viewprofilepage/user-id/492874)

I updated the test automation with audit log reporting and it seemed to work here.

As you can see this has worked when re-fetching the details from the the CS-10 form reference.

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

Maybe it is what [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) is saying and the trigger is firing too quickly causing it not to capture any data. I have tried editing the automation that does the equation and have the re-fetch data straight after the trigger is activated but I get the same result as previous.  
![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338893i0B6064F7EA6F6491/image-size/large?v=v2&px=999 "image.png")

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

Thanks

Ethan


author: Bill Sheboy
body: When you review the issue details, what do you see *in the comment*? Please post an image of that view. Thanks!


author: Ethan Bhardwaj
body: [@Tim Kopperud](/t5/user/viewprofilepage/user-id/492874) [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

Thank you both this has now worked I have added a 10-second delay after the Trigger into a re-fetch issue data and this has outputted the correct comment for the fields. the audit log also reflects this. ![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338897i69797D8611546C01/image-size/large?v=v2&px=999 "image.png")

All the best Ethan


author: Tim Kopperud
body: Hi [@Ethan Bhardwaj](/t5/user/viewprofilepage/user-id/5553391), great news. Thanks for accepting the answer.

TimK


author: Dick
body: Hi Ethan,

I have a similar calculation using custom fields.   
My calculation has the **issue** reference in it:   

{{#=}} {{issue.customfield_12800}} + {{issue.customfield_12805}} {{/}}

I suspect that if you only use {{customfield_xyz}} the value gets interpreted as a string.

comments: author: Ethan Bhardwaj
body: Hi [@Dick](/t5/user/viewprofilepage/user-id/4586768) ,   

Both the Custom fields are set as Custom Number fields so they shouldn't be Strings looking into the XML code of the form you can see that the fee is being set to the appropriate value and the remaining balance custom field is also the correct input.  

So I am uncertain why when using {{#=}}{customfield_xxxx}} + {{customfield_xxxx}}{{/}} is not outputting in this case "27.95"  
![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338157i3EEC28F208C779BB/image-size/large?v=v2&px=999 "image.png") ![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/338156i384D5AA5DA30034B/image-size/large?v=v2&px=999 "image.png")


author: Dick
body: I suspect the variable you refer to gets the correct type ONLY if it's related to a full object (which the issue is).

I'm calculating the Weighted Shortest Job First (WSJF) using dropdowns and a calculation similar to the one I gave above.

Try it??


author: Dick
body: In your own examples, a full reference to the issue yields a correct value. Removing said reference doesn't work.   

I really think the reference to the issue is important here.


author: Ethan Bhardwaj
body: Hi [@Dick](/t5/user/viewprofilepage/user-id/4586768)  

we have added the issue. to the custom field ID and we have reviewed the Audit log and have received back the following error "Missing parameter(s) for operator +: 25.0 +"   
In this instance, it does not add the "Activation fee" Custom field even though it is being set, as shown in the XML above.  

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


author: Dick
body: The re-fetch that [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) suggested is essential here. One of your fields is not carrying the value.


author: Dick
body: Looking at the above log, it's the commenting of the issue (last step) where the codes throws an error.

When commenting, one typically requires an output that resembles more of an html text. You might want to show the newly calculated (and re-fetched!!) content of the field you just edited successfully:

{{issue.customfield_10037}}


author: Dick
body: Ah, I see the **issue** reference worked :)


author: Ethan Bhardwaj
body: please read above.

comments: author: Ethan Bhardwaj
body: Hi Tim,

Unfortunately, the change in capitalisation hasn't affected the result.

Ethan


Tags: cloud

custom-field

jira-cloud

math