snippet on mass actions works only once

edited July 2017 in Questions
I have a mass action which comprises of a series of actions, out of which one runs a javascript snippet to get the list of selected rows from the model in context and create records in another model - 'APF_onboardingProduct'.

var params = arguments[0],
$ = skuid.$,
list = arguments[0].list,
selectedItems = list.getSelectedItems();
var modelORProducts = skuid.model.getModel('APF_onboardingProduct');
if (selectedItems.length > 0){
    $.each( selectedItems, function( i, item ){
        var rowORProducts = modelORProducts.createRow();
        modelORProducts.updateRow(rowORProducts, {Product__c : item.row.Id});
    });
    modelORProducts.save({callback: function(result){
        if (result.totalsuccess){
            console.log('modelORProducts saved');
        }
        else {
            console.log('modelORProducts not saved');
        }
    }});
}

Once the snippet is executed, I have 2 other actions that requery both the models in question. Everything works beautifully until here. But when I select a few more rows and try to do the same, it does nothing.

Also, on the first instance when it works correctly it saves the model correctly but doesn't log anything that I have within the save callback. The 2nd instance when it doesn't work correctly, it logs the save callback as 'modelORProducts saved'. 

Can someone please help me with this?

Comments

Sign In or Register to comment.