Update a formula field if lookup value changes on table row

Hello Louis -

The good news is that what you are trying to accomplish is possible.  Unfortunately, depending on your situation, the solution could become rather complex.

A few thoughts…

1) If the Formula on your primary table is a straight output of a field from the lookup field itself with no additional logic applied, then instead of displaying the formula field from your primary table in the field editor, create a template field and reference the value from the lookup (e.g. Inventory_Item__r.Field__c).  If this is the case, you will need to make sure to include Inventory__r.Field__c in both your model field properties and in the search fields for the lookup field making sure to select the “return field value” option (this is the default behavior).

2) If your formula does something more than just displaying the raw value from the lookup field itself (eg. string concat, etc.), this is where it gets more complicated.  Skuid treats formula fields as read-only so even if you update your model programmatically, the field editor won’t re-render the formula field.  You can work around this by using the approach referenced at https://community.skuid.com/t/read-only-field-not-rendering-properly-after-update.  If you follow the steps there and then programmatically update the model (or using action framework), the formula field should re-render automatically after them model row is updated.  

3) Taking #2 a step further, if your formula field relies on other data in the record to derive it’s value, in order to accurately update the model with the new field value, you’ll need to make sure that all necessary fields to properly evaluate the formula are in your model fields and in any lookup field search fields marked to return the value.  

If I’m understanding what you are after, what this really comes down to is how complex the formula is that you are trying to manage client side.  There is no way for skuid to regenerate this formula real-time since it’s evaluated on the server by SFDC and all Skuid knows is the resulting value.  In order to keep the value in that field current, you need to update the model with the current value as other things in the model change.  In essence, you’re replicating the logic from your formula in Skuid/javascript.  

In our solution, in certain situations, we’ve replicated formulas and even rollups so that the client is always “current” as the data on the screen changes.  This isn’t something I’d encourage be done unless there is a very strong need for it - the reason for this is that depending on the complexity of the formulas and relationships, supporting and maintaining this code could become “costly” and it is prone to error.  That said, it can definitely be accomplished and if your situation is just a simple display of the property of the lookup field itself without any additional logic, then it’s fairly straightforward by using a template field instead.