Adding 2 custom fields together not working?

Ethan Bhardwaj
Contributor
July 26, 2024

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

This code is not working

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

4 answers

2 accepted

2 votes
Answer accepted
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.
July 26, 2024

Hi @Ethan Bhardwaj -- 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

1 vote
Answer accepted
Tim Kopperud
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 26, 2024

Hi @Ethan Bhardwaj, 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

Tim Kopperud
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 26, 2024

@Ethan Bhardwaj, try small letters. customfield_xxxxx, not customField_xxxxx.

TimK.

Ethan Bhardwaj
Contributor
July 26, 2024

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
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
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 

Ethan Bhardwaj
Contributor
July 26, 2024

Hi @Tim Kopperud , 

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

Ethan

Tim Kopperud
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 26, 2024

Hi @Ethan Bhardwaj, 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

Ethan Bhardwaj
Contributor
July 26, 2024

Hi @Tim Kopperud

no problem, here is the code for commenting an outcome.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


Tim Kopperud
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 27, 2024

@Ethan Bhardwaj, 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
    Execute this rule manually during investigation:
    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

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

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

Like Ethan Bhardwaj likes this
Ethan Bhardwaj
Contributor
July 29, 2024

Hi @Tim Kopperud , 

Thank you for your response, 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.pngimage.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

I hope this Log helps

- Ethan

Tim Kopperud
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 29, 2024

Hi @Ethan Bhardwaj , try using {{customfield_10037.value}} 

TimK 

Tim Kopperud
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 30, 2024

Hi @Ethan Bhardwaj, 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 and @Dick 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

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

Ethan Bhardwaj
Contributor
July 30, 2024

Good Morning @Tim Kopperud 

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

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

-Ethan

Tim Kopperud
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 30, 2024

Hi @Ethan Bhardwaj, 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

Like Ethan Bhardwaj likes this
Ethan Bhardwaj
Contributor
July 30, 2024

Hi @Tim Kopperud 

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.pngimage.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.pngimage.png

- Ethan

Tim Kopperud
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 30, 2024

Hi @Ethan Bhardwaj, 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.

Like Ethan Bhardwaj likes this
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.
July 30, 2024

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.

Like Ethan Bhardwaj likes this
Ethan Bhardwaj
Contributor
July 30, 2024

Hi @Tim Kopperud 

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

Maybe it is what @Bill Sheboy 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

image.png

Thanks 

Ethan

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.
July 30, 2024

When you review the issue details, what do you see in the comment?  Please post an image of that view.  Thanks!

Ethan Bhardwaj
Contributor
July 30, 2024

@Tim Kopperud @Bill Sheboy 

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

All the best Ethan

Like Tim Kopperud likes this
Tim Kopperud
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 31, 2024

Hi @Ethan Bhardwaj, great news. Thanks for accepting the answer. 

TimK

Like Ethan Bhardwaj likes this
0 votes
Dick
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 26, 2024

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.

Ethan Bhardwaj
Contributor
July 26, 2024

Hi @Dick , 

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  image.png

Dick
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 26, 2024

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??

Dick
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 26, 2024

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.

Like Ethan Bhardwaj likes this
Ethan Bhardwaj
Contributor
July 26, 2024

Hi @Dick

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

Dick
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 29, 2024

The re-fetch that @Bill Sheboy suggested is essential here. One of your fields is not carrying the value.

Like Ethan Bhardwaj likes this
Dick
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

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

 

Dick
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

Ah, I see the issue reference worked :)

 

Like Ethan Bhardwaj likes this
0 votes
Ethan Bhardwaj
Contributor
July 26, 2024

please read above.

Ethan Bhardwaj
Contributor
July 26, 2024

Hi Tim, 

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

Ethan

Suggest an answer

Log in or Sign up to answer