javascript save issue with deferred / promise approach

  • 1
  • Problem
  • Updated 4 months ago
  • (Edited)
I'm struggling to implement the deferred / promise approach as outlined here, here, and here

My use case is to:

1) Mass create rows with a different lookup value in each row
2) Update / Refresh a second model
3) Use a value from my second model as the lookup value in each row
4) SAVE!

I can get it to do steps 1-3 perfectly, but can't get it to save my new rows.

I've tried a bunch of different things...(e.g. chaining .then(), putting save action as next action in sequence, etc)...nothing so far...

Any advice would be much appreciated.

var params = arguments[0];
var step = params.step;
var $ = skuid.$;
dfd = new $.Deferred();
// Get Reference to Models to mass create newGoals from templateGoals var TemplateGoals = skuid.$M('TemplateGoals'); var newGoals = skuid.$M('NewGoals'); // Get Reference to context model and filterable condition which will be used to query and store the Template Goal // that matches each goal in my newGoals model during iteration var matchingTemplateGoal = skuid.$M('ContextGoal'); var contextgoalNameCondition = matchingTemplateGoal.getConditionByName('GoalName'); // For each New Goal, query it's matching Template Goal and // update the value of the Template_Goal__c lookup with the Id of the matching Template Goal $.each(TemplateGoals.getRows(),function(){ // Set condition of ContextGoal model to match this current goal's Goal__c value matchingTemplateGoal.setCondition(contextgoalNameCondition, this.Name ); $.when(matchingTemplateGoal.updateData()).then(function(){ // Get values of Context Goal var matchedTemplateGoalId = matchingTemplateGoal.getFieldValue(matchingTemplateGoal.getFirstRow(), 'Id'); var matchedGoalName = matchingTemplateGoal.getFieldValue(matchingTemplateGoal.getFirstRow(), 'Goal__c', true); newGoals.createRow({ doAppend: [true], additionalConditions:[ {field : 'Template_Goal__c', value : matchedTemplateGoalId}, {field : 'Goal__c', value : matchedGoalName} ]}); return; }); }); return dfd.promise();               
Photo of Conlan O'Rourke

Conlan O'Rourke

  • 3,280 Points 3k badge 2x thumb

Posted 4 months ago

  • 1

Be the first to post a reply!