I suspect what I’m trying to do is in here but I’m not having any luck with it.
Here’s what I’m looking to do:
I have a lookup field in a table (Inventory_Item__c). I also have a currency formula field in the table which references a field on the looked up record (Price_current__c). After selecting a record in the lookup the formula field is only populated when the model is saved.
I’d like the formula field to update when the lookup is updated prior to the model being saved. If easier, the formula field need not be a formula field and could just be a lookup__r.fieldname__c reference using skuid.
I’m guessing I need to use a snippet field renderer combined with an event listener. Would someone be able to point me in the right direction as to how to put this together?
I wonder if you could
(1) create a model for the Inventory_Item__c object
(2) add a conditional filter on the Id
(3) set and activate the filter
(4) query the model to get Price_Current__c
(5) then update the the table model with the Price_Current__c
Someone could probably articulate this better than me but this may work.
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.skuidify.com/skuid/topics/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.
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.
Irvin, Barry - thank you for your responses.
I thought the template trick (adding in the required field as a search field to the lookup and displaying it as a template - neat!) might be the solution - it works but unfortunately I also need to summarise the results in the table which doesn’t seem to be an option with a template field.
I’m looking for live updates because I want users to be able to add line items to a transaction record and report costs to a customer before saving the transaction once the customer has agreed on the products and prices.
Barry - I’ll take a crack at your 2nd thought above and see how I get on.
Golly - I’m utterly stumped and needing rescue. Does anyone have an example I can use to get me going?
So - I’m looking to update a lookup field on a row in a table and have a custom-render (which can be column summarised) show a field from that related lookup - all prior to a save.
I’m also looking to have another column which does some basic math on that value.
Here’s the model:
- The rows on the table are Inventory_Adjustment records which have a lookup to Inventory_Item.
- The item record has a price field which I want to show on the table row and update when the lookup value is updated. I would use a template field except I need to be able to summarise this data which can’t be done with a template.
- The adjustment records have a quantity field and I’d like to be able to multiply the quantity of the adjustment with the price of the item to get total price.
I’d like to sort the JS myself but if someone could post some example code that I could use as an example that’d be awesome.
Hello Louis -
I put together a very small sample, hopefully this will get your going.
A few things to note:
- On page load, we make sure the formula fields are marked creatable/editable so that skuid automatically rerenders the field on update
- We use the action framework to call a snippet (handleAccountChange) when the account field changes
- We make sure that the fields we need for evaluation are in our model and in the search fields marked to return
To get the below to work, you’ll need to add a field called “TestFormula” to your Contact object.
In the sample I just do a string concat but of course you could do any type of operation including calculations like you need in your case.
Barry - I just checked your test page and it’s working perfectly. I’ll update my own page tomorrow using this as a guide and will let you know how I get on.
Thanks so much for sharing the sample - champion indeed!
Glad to hear it worked Louis, good luck with the changes to the actual page, look forward to hearing good results!
Thank you very much Barry!
Yeeeeaaahhhooooooo! Job’s a good’n Barry. Nailed it!
Thanks so much - this makes everything much more intuitive as the user can edit values and view calculations in realtime rather than having to save the model first and then edit/delete items, save again, etc.
Gee, I love me some Skuid.
I’m really liking the animated gif…
Awesome news Louis, great work!