Formula value not correct until record is updated

I have an app that is using a numeric equation to multiply 3 values. One of those values is retrieved from a connected object. The formula works but not until I force it to refresh by submitting (via the record object view) the formula again by clicking a field in the record and then clicking submit.

This formula is used on the add of a new record. After submitting, the connected information is retrieved via record rules, so it doesn’t exist yet for the initial submit.

Does anyone have a solution for getting around the order of when things happen?
Thanks.

It may be something @Sunny_Singla has an idea about using code :man_technologist:

Hello @CarlHolmes ,

Possible using javascript as I understand. We need to call a function when the connection field and the other 2 depended on the fields’ value change.

But I think if we don’t want to display it on the front end at the time of creating records then we can achieve this using equation.

Regards,
Sunny Singla

Hi @KathyHiggi39830,

I have run into this limitation before, if I am understanding correctly.

I don’t believe you can use the record rules to “insert a connected record” and then immediately return a value from the new connected record in one button press.

I don’t know your exact situation, but this is likely something you are going to need to do using the API, or a service like Make or Zapier, to update the record with the new connected value you are creating. Generally, you would be setting up something to watch when a record A is created from the live app, that will then search for the new connected record B and pull the value back into record A so that the formula updates.

For example, in one of my scenarios, my users are submitting a monetary value each month for their reports into object A. This indirectly updates a YTD sum formula in a connected object B in the submission step, then I use Make to pull that YTD sum value back from the (secondary) connected object B into the (primary) report record in object A for each month’s submission to keep the running total each month, as well as values that are used for calculations in object A, which I think is what you are trying to do.

You cannot add simply a second “Update this record (A)” step after inserting a connected value (B) like that that with record rules; it does not work like that, or if it does, you will run into situations where your primary record submission (A) is completed before the secondary connected value (B) exists, like you have said.

I hope that makes sense. You can kind of replicate this using tasks, but this sounds like it would be a great reason to check out Make and Zapier and see how much they can expand your use of Knack. :slight_smile:

1 Like

Thanks for your thoughts on this. Last week I tried using Make and the issue remains, that the underlying table view doesn’t get updated with the total amount quick enough, even when I do the math in Make. The add is accomplished via a pop up. When it is closed (I force them to manually close the pop up), the record still is not done updating and so the table is incorrect.
I added a refresh table button in the menu (using a JS URL) and that works but I don’t like it… lol.
I know just enough JS to be dangerous. If anyone has ideas of how to do this with JS (once the total is updated to force a refresh of the table) I’d love to try to make it work.
Thanks so much for your ideas!

for anyone still running into this issue, @Callum.Boase had the solution that worked for me.

in my case:
-i’ve got multiple text formulas in an object…at least one of which references a connected object.
-the display field for this object is set by conditional rules, which reference the text formulas above.
-i believe i was having the same issue as the OP, where a newly created record (via a form in the live app) didn’t exist yet because the conditional display field wasn’t updating in time.

Callum’s suggestion was to re-order the fields in the builder so that all the (text formula) fields that the display field relies on are ABOVE the conditional display field. This can sometimes influence how quickly & what order Knack does updates to values in.

in my case i put the text formulas FIRST in the builder, and my conditional display field last. this made everything update immediately and i haven’t had any issues with this since. hope that helps somebody, and thanks to my knack expert @Callum.Boase! he’s helped me out of several jams like this one.

2 Likes

That’s a great idea to try. Next time I’m in that app I will make that modification and see how it works for me. Thanks so much for sharing!