Update date field from another model

  • 2
  • Question
  • Updated 1 year ago
  • Answered
I have 2 models:  Program and Timeline, both have a field named Mail_Date__c.   When the Program model Mail_Date__c is updated, need Timeline model Mail_Date__c to update to that same date.   Action Framework only allows specific dates, so am using Snippet, but am unable to find the correct syntax.   Here is what I have so far that is not working:

var params = arguments[0], $ = skuid.$;
var model = skuid.$M('Timeline');
var row = model.getFirstRow();
model.updateRow(row,{


Mail_Date__c: Program__r.Mail_Date__c
});

I assume the last line needs help.  Thanks!
Photo of ann kukich

ann kukich

  • 112 Points 100 badge 2x thumb

Posted 1 year ago

  • 2
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Is the Timeline model is related to the Program model with the Program__c field?
Do both models have the Mail_Date__c fields?

Assuming yes to both above, then the issue is that Program__r.Mail_Date__c in Timeline model isn't yet updated with the Mail_Date__c on Program model. It would still have the value it had when the page loaded. That's even if you saved the Program model. You could of course requery the Timeline model, but that's a poor UX.

I'd just add the Program model and row to the snippet in order to use it in the updateRow function. ie. programModelRow.Mail_Date__c in place of Program__r.Mail_Date__c

Cheers
Photo of Ann Kukich

Ann Kukich

  • 1,316 Points 1k badge 2x thumb
Yes, the Timeline model is related to Program model with Program__c, and both models have the Mail_Date__c fields

Tried programModelRow.Mail_Date__c in place of Program__r.Mail_Date__c and still not working.

Running a test, I am able to update the Timeline field to 'null' without problem (below)
var params = arguments[0], $ = skuid.$;
var model = skuid.$M('Timeline');
var row = model.getFirstRow();
model.updateRow(row,{


Mail_Date__c: null 
});
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
You may be able to accomplish this with a flow, process, or workflow if you can't get the snippet to work.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Yup. Process will do it the easiest in SF.
Photo of ann kukich

ann kukich

  • 112 Points 100 badge 2x thumb
Thanks for all of the suggestions!  Went with Salesforce process builder and works great!