Probably something simple but this snippet works in my V1 page but not the V2 version. Is there some syntax I am missing?
var params = arguments[0],
$ = skuid.$,
dfd = $.Deferred(),
list = arguments[0].list,
items = list.getSelectedItems(),
JobModel = skuid.$M('RECONJob'),
JobRow = JobModel.getFirstRow(),
PPModel = skuid.$M('ProcessProducts'),
PPModelCond = PPModel.getConditionByName('PId'),
SEPModel = skuid.$M('NewScopeEntryProcesses'),
SEPPModel = skuid.$M('ScopeEntryProcessProducts'),
CSEPModel = skuid.$M('CurrentScopeEntry'),
CSEPModelRow = CSEPModel.getFirstRow();
//loop through selected processes
$.each(items, function(pIndex,item){
//copy process into scope entry as scope entry process
var conditions = [
{ field: 'RECON__Process__c', value: item.row.Id},
{ field: 'RECON__Scope_Entry__c', value: CSEPModelRow.Id},
{ field: 'RECON__Sequence__c', value: item.row.RECON__Sequence__c},
{ field: 'RECON__Contract_Price__c', value: item.row.RECON__Contract_Price__c}
];
SEPModel.createRow({ additionalConditions: conditions });
});
//loop through newly created scope entry processes
$.each(SEPModel.getRows(), function(sIndex,sRow){
//query process products based on current scope entry process value for RECON__Process__c
PPModel.setCondition(PPModelCond,sRow.RECON__Process__c);
$.when(PPModel.updateData())
.done(function(){
if(PPModel.data.length){
$.each(PPModel.getRows(), function(ppIndex, ppRow){
//copy product into scope entry process as scope entry process product
var conditions = [
{ field: 'RECON__Job_Process__c', value: sRow.Id},
{ field: 'RECON__Product__c', value: ppRow.RECON__Product__c },
];
SEPPModel.createRow({ additionalConditions: conditions });
// return promise once all products for all scope entry processes have been looped through
if ((ppIndex == (PPModel.data.length - 1)) & sIndex == (SEPModel.data.length -1)){
dfd.resolve();
}
});
} else {
if (sIndex == (SEPModel.data.length -1)){
dfd.resolve();
}
}
})
.fail(function(){
console.log('Something went wrong querying PPModel');
dfd.reject();
});
});
return dfd.promise();