Question updating field in one model with a field from another model

  • 1
  • Question
  • Updated 4 years ago
  • Answered
Hello -

To keep it simple, say I have two models and fields
Model A  --> Field
Product1UpContract -->  Price_Per_Case__c
and
Model B  -->  Feild
Product1ContractPricing  --> UP_Contract_Uplift__c

Note - Model B also has a field called Price_Per_Case__c

I would like to update the Product1ContractPricing  --> UP_Contract_Uplift__c field with the Product1UpContract -->  Price_Per_Case__c field.

Everything I read seems to say this should be done with the action framework.

I set the Action up on the Product1UpContract  (Model A) as shown below.  The action is firing but it seems like it is updating the UP_Contract_Uplift__c field with the Price_Per_Case_c  from Model B not Model A.   Any thoughts?


Photo of Jeffrey Lawler

Jeffrey Lawler

  • 1,454 Points 1k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Jeff, just a quick check, it looks like the "Initiating Event" for this Model Action is "Model requeried" --- is that what you want? "Model requeried" takes place when the user searches or filters a Model, or clicks a button that specifically requeries a Model. Do you perhaps want this update sequence to take place whenever the user changes the Price per Case field on a particular row? Can you spell out in more detail what the desired "initiating event" is for this scenario?
Photo of Jeffrey Lawler

Jeffrey Lawler

  • 1,454 Points 1k badge 2x thumb

Zach,
This is similar to what you helped me with earlier.  See below:  When a user enters a value for the sold to account, it kicks off an action framework (see below) which passes the sold to number to a number of conditions and then queries the Product1ContractPricing model and the Product1UpContract model.  If there is a value returned from the Product1UpContract query for Price_per_Case__c  I want to display that on the Product1ContractPricing model/table in the UP_Contract_Uplift_c field. 
There will only ever be one value  returned from the Product1UpContract model which would be displayed for each line in the  Product1ContractPricing table (if there is more then one).

Hopefully that make sense?

Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Your action is kicked off from Model B and you use simple merge syntax {{Price_Per_Case__c}} to provide the value. This means that the value to be placed in the row is going to come from Model B  (I believe from the first row of model B).  You need to use global merge syntax to call data from Model A.  That looks like  this:   {{$Model.Product1UpContract.data.0.Price_Per_Case__c}}
Photo of Jeffrey Lawler

Jeffrey Lawler

  • 1,454 Points 1k badge 2x thumb

Rob,


It doesn't seem to work either way - I put the action on Model A and try to pull the data from model B using the global merge syntax {{$Model.Product1UpContract.data.0.Price_Per_Case__c}}  or put the action on Model B and 'push' the data to Model A using the global merge syntax {{$Model.Product1UpContract.data.0.Price_Per_Case__c}}.   ???

Photo of Jeffrey Lawler

Jeffrey Lawler

  • 1,454 Points 1k badge 2x thumb

All,


Rob helped me out to resolve this so I thought I would post the solution here.  The data I was trying to get to was on a child object so the global merge syntax had to be change a bit.  Here is the path to be able to get to data on a child object via merge syntax:


{{$Model.PrimaryModelName.data.0.ChildObjectName.records.0.FieldName}}



Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Thanks for posting this for posterity..