Snippet from V1 not working in V2

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();

Hey @Chad_Gill ,

So I can understand what is going on, is the code snippet returning any specific error or warning message when you run it?

Thanks,

not that I see. I am out of my depth once we get to that point Can zoom you and show if have a sec

Some background on moving JS code from V1 to V2.

In V2 - any snippet that manipulates the DOM (controls the visual appearance of the page) will not work. WE’ve changed the way the page components are implemented and so you can’t reuse those sorts of snippets.

But - snippets that manipulate model properties should work. Adding rows, updating values, all that… Shoudl be good.

So on cursory review - this snippet should work. But there are so many ways it could go sideways.

Do you have it connected to the right type of JS resource? Is the snippet even firing? Add a Console log statement to the beginning of the snippet like this:

  • console.log ("I'm working");
  • Are all the models and conditions set up as described in the snippet. There are lots of hard coded models, conditions and fields in the snippet. they are not also in the page - it won't work.

I’m not 100% sure, but this looks like a really old recommendation we used to give out for creating a mass set of child records and prepopulating data from thier parent rows. I’m pretty sure this could now be done as an action sequence in a completely declarative fashion. That would remove the Javascript entirely from the equation and provide a solution that a non-coding skuid builder would understand and be able to maintain going forward. That would be my recommendation.

Makes sense and I like the non-code approach, SKUID!!

Hey Chad,

This should work. Did you ever ask me to look at this?

Pat