Update Parent Records for Each Child Record in Table

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I have a table of junction objects (ConsultationMedRec__c).  Each is related to a different MedRec (MedRec__c).  When I update the Order_Hidden__c field on the Consultation MedRec, I want the Order_Temp__c field on the related MedRec to be updated.  

I've tried a couple of different Javascript snippets, but none seem to be working.  I feel like I'm missing something - this seems like it should be pretty easy to do.  Here's what I'm working with now: 

var params = arguments[0]; var $ = skuid.$;
var models = skuid.model.map();    
var consultationmedrecs = models.ConsultationMedRecs;

var rowsToUpdate = {};

$.each(consultationmedrecs.data, function(){
    rowsToUpdate[this.MedRec__c] = { Order_Temp__c: this.Order_Hidden__c };

consultationmedrecs.updateRows( rowsToUpdate );
Photo of Elissa Bradley

Elissa Bradley

  • 1,786 Points 1k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,686 Points 5k badge 2x thumb
The problem is that you are updating the Consultation Med Rec model instead of the Med Rec model.