Skip to main content

I’m trying requery a model and compile all the data into a few tables. I’m finding, however, that my model’s condition isn’t being updated correctly.  Here’s my code:

----------------------------------------------------------------------------------------------------


var interviewerSet = new Set();<br /><br />&#47;&#47; get list of all reviewers $&#46;each(scoreModelInit&#46;data, function(i, row) { interviewerSet&#46;add(row&#46;Interviewer_Override__c); }); &#47;&#47; create Score_Object for each record interviewerSet&#46;forEach(function(interviewerId) { console&#46;log(interviewerId); scoreModelFinal&#46;setCondition(conditionName, interviewerId); console&#46;log(scoreModelFinal&#46;conditions;1]); &#47;&#47; this output remains the same $&#46;when(scoreModelFinal&#46;updateData())&#46;then(function() { scoreList&#46;push(new Score_Object()&#46;CreateObject(scoreModelFinal&#46;data)); }); });<br />

----------------------------------------------------------------------------------------------------

So I’m iterating through this set and using the values to set my condition and requery, but the condition is always stuck on the last value I give it.

Here are some of the logs I’m getting:


interviewerId : 0038000000YJgmYAAT scoreModelFinal&#46;conditions;1] : { encloseValueInQuotes: true field:"Interviewer_Override__c" fieldTargetObjects:"Contact" inactive:false label:"" name:"Interviewer_Override__c" noValueBehavior:"deactivate" operator:"=" originalInactive:false originalValue:"" row:0 state:"filterableon" type:"fieldvalue" value:"00380000012V8SjAAK" &lt;== THIS VALUE SHOULD BE 0038000000YJgmYAAT values:undefined }<br />


The condition stays at 00380000012V8SjAAK, even though this is the last value I’m passing in!  Any advice on how to get these model query calls to execute?


Thanks!
Eulogio

Looks like you need to move the setCondition out of the loop.  The logic should be to set the array variable, enter the loop where you push values to the array, then outside the loop use the setCondition with set of values in the array.  The condition on the model should be set to multiple values. 


Thanks for the reply John! Your advice was helpful, but didn’t address the issue I was facing. I was just not handling promises correctly and doing things out of sequence.  A combination of following your advice and reordering my code execution a bit solved the issue.


Hey Eulogio, I am stuck on the same thing.  Would you mind sharing your solution?


Reply