snippet on mass actions works only once

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?

atlantabadi,

Take a look at this post in the community-> https://community.skuid.com/t/save-model-javascript-callback-function

Your 2 other actions may be running before the save has completed.  Try switching to the deferred promise method shown in the post I linked.

Thanks,

Bill

Thanks a lot Bill. That worked like a charm. Also thanks to you I got to learn something new today.