Merging a formula value in a new row created using a row action

  • 2
  • Question
  • Updated 3 years ago
  • Answered
Morning Folks!

I'm using a row action on a table to create a new row whilst populating its fields with data from the original row. This is working fine except for using a formula field on the original row to populate a field on the new row.

I've tried re-querying the model before updating but that hasn't fixed it - the field comes up blank.

Any ideas?

Cheers!

Louis
Photo of Louis Skelton

Louis Skelton

  • 4,786 Points 4k badge 2x thumb
  • fabaroonie

Posted 4 years ago

  • 2
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
Is the field in the model from the original row?
Photo of Louis Skelton

Louis Skelton

  • 4,786 Points 4k badge 2x thumb
Yes, just double-checked. At first I thought that Skuid was processing the row creation before Salesforce had a chance to evaluate the formula field, but even if the formula field's determining values aren't changed as part of the save the value still isn't populated.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
So only some values are making it into the new row?

Is the formula field visible to you? ie. field level security
Photo of Louis Skelton

Louis Skelton

  • 4,786 Points 4k badge 2x thumb
All values are making it except for this formula field. And yes, I've got field level access.

What I'm trying to do is take the original row, click a row action which drops down a drawer which allows you to enter a number. Click a button on the drawer which then saves that row and creates two new rows: one which has a 'Quantity' field populated using the number entered in the drawer, another which has the same 'Quantity' field populated using a formula which references the number entered in the drawer.

It's this second row that's not populating.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
er ... uh .... lost me. Screenshots or video would help.
Photo of Louis Skelton

Louis Skelton

  • 4,786 Points 4k badge 2x thumb
Working on it! Cheers Pat.
Photo of Louis Skelton

Louis Skelton

  • 4,786 Points 4k badge 2x thumb
Here we go...!
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
Those fields in the drawer. What model/row do they belong to? Do they get saved?
Photo of Louis Skelton

Louis Skelton

  • 4,786 Points 4k badge 2x thumb
Yeah, the fields in the drawer belong to the same model as the rows being created. The drawer fields should get saved with the first 'Save Model' action which proceeds the row creation actions. I've tried requerying the model inbetween the save and the new rows but that didn't help.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
Same model and row?

I ask because the moment you make a new row in that model the context merge fields change to that row.

So, prior to making rows, save the row and pull that original row into its own model and create the 2 new rows from it. Ie. {{$Model.modelname.data.0.fieldnames}}
Photo of Louis Skelton

Louis Skelton

  • 4,786 Points 4k badge 2x thumb
For anyone else that tries to do things the wrong way - as I was - this here and Pat's next post is the fix.
Photo of Louis Skelton

Louis Skelton

  • 4,786 Points 4k badge 2x thumb
Cheers Pat, I'll give that a try. I get how to use {{$Model.modelname.data.0.fieldnames}} once I've got the row in the model, but how do I allocate the saved row into its own model?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
Model
Set max records to 1.
Create condition of Id = "" Filderable Default Off
Add fields as necessary.

Actions to add before creating two new records.
Photo of Louis Skelton

Louis Skelton

  • 4,786 Points 4k badge 2x thumb
I've changed it so that I'm saving the original row into a new model and referencing that row in creating the two new rows but it's still populating all fields except the field that originates from the Formula field. I might try changing the formula into a workflow - see if that works any better.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
No. No. The formula works. Something else  is going on.
Display that new model and row on the page to ensure that you can indeed see the data. Make sure to use nothing but {{$Model.modelname.etc...}} 
Photo of Louis Skelton

Louis Skelton

  • 4,786 Points 4k badge 2x thumb
Yeehaa! My mistake - it does work, I'd forgotten to add the formula field to the model that the original row gets inserted into as part of the chain of actions. *Looks sheepish*...

Thanks for your patience Pat - you're a stalwart and a trooper. If I could, I'd buy you beer.

Cheers!
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
I second that motion.  We should buy Pat beer. 
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,674 Points 20k badge 2x thumb
You said "We should buy Pat beer"
You didn't say "We should buy Pat a beer"
Really should say "We should buy Pat a lifetime supply of Stronbow Cider"
Photo of Peter Bender

Peter Bender, Champion

  • 6,246 Points 5k badge 2x thumb
Just to be clear for others that had this same issue, as this can be confusing:

To use a row action to create a new row/record and default/populate a field with data from the original/parent row/record, the original/parent model needs to contain the field that you are referencing. In other words, the new/child model does NOT need to contain parent__r.source_field__c, but the parent model DOES need to contain source_field__c. The new/child model does need to contain the target field into which the default data is being populated, of course.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Thanks for the clarification Peter.  You are correct. 
(Nice to see you in these parts again. We've missed you)
Photo of ddeveaux

ddeveaux

  • 1,202 Points 1k badge 2x thumb
Wow so glad I found this. Been pulling my hair out for a bit wondering why I couldn't populate 2nd field on my action. Not sure I would have ended up here!