Copy/add selected rows within a drawer from one model to a different model

  • 6
  • Idea
  • Updated 2 years ago
  • (Edited)
I noticed there wasn't a complete script available in the forums that allowed for this, so I wrote one. This can also be used to copy selected rows in any models table to another model.

The source model in this example is LineItemsBundle, which is conditioned and queried using action items. (Activate Condition & Set Value, Query Model, Open Drawer). It didn't work particularly well using Before Load actions, so manual actions were used instead. The destination model is QuoteLineList. Selected rows from within the draw will be added to the QuoteLineList model with variables set in the script and then saved. Hope this helps!

var params = arguments[0],
$ = skuid.$, models = skuid.model.map(); // grab ids of all selected rows var Ids = skuid.$.map(arguments[0].list.getSelectedItems(), function(item){ return item.row.Id; }); // model to add seleted rows from var bundlelines = skuid.model.getModel('LineItemsBundle'); // model to add to var quotelines = skuid.model.getModel('QuoteLineList'); // for each selected row, add a new row $.each(Ids, function(){ var currentId = this; // get selected row data var bundleRow = bundlelines.getRowById(this); // set variables for selected row field(s) var itemId = bundlelines.getFieldValue(bundleRow, 'Item__r.Id'); var itemQuantity = bundlelines.getFieldValue(bundleRow, 'Quantity__c') var bundleName = bundlelines.getFieldValue(bundleRow, 'Bundle_Name__r.Name'); // create new row with selected row variables var quotelinerow = quotelines.createRow({ additionalConditions: [ {field: 'SCMC__Item_Number__c', value: itemId, operator: '='}, {field: 'SCMC__Quantity__c', value: itemQuantity, operator: '='}, {field: 'AC_Bundle_Group_Name__c', value: bundleName, operator: '='} ] }); }); // save updated model quotelines.save({callback: function(result){ if (result.totalsuccess) { //console.log(quotelines); } else { console.log(result.insertResults); console.log(result.updateResults); console.log(result.deleteResults); } }});
Photo of Oliver Sinfield

Oliver Sinfield

  • 922 Points 500 badge 2x thumb

Posted 3 years ago

  • 6
Photo of Erik Wahlberg

Erik Wahlberg

  • 2,156 Points 2k badge 2x thumb
Adapted this snippet for use in transferring Opp LineItems to the Quote being created. Below are the changes I made to the snippet. If anyone's having issues with quotes in Skuid shoot me a message and i'll send you a sample page I put together.

var params = arguments[0],
$ = skuid.$,
models = skuid.model.map();

// grab ids of all selected rows
var Ids = skuid.$.map(arguments[0].list.getSelectedItems(), function(item){
return item.row.Id;
});

// model to add seleted rows from
var bundlelines = skuid.model.getModel('LineItems');

// model to add to
var quotelines = skuid.model.getModel('QuoteLineItems');

// for each selected row, add a new row
$.each(Ids, function(){
var currentId = this;

// get selected row data
var bundleRow = bundlelines.getRowById(this);

// set variables for selected row field(s)
var itemId = bundlelines.getFieldValue(bundleRow, 'PricebookEntryId');
var itemQuantity = bundlelines.getFieldValue(bundleRow, 'Quantity')
var bundleName = bundlelines.getFieldValue(bundleRow, 'UnitPrice');

// create new row with selected row variables
var quotelinerow = quotelines.createRow({
additionalConditions: [
{field: 'PricebookEntryId', value: itemId, operator: '='},
{field: 'Quantity', value: itemQuantity, operator: '='},
{field: 'UnitPrice', value: bundleName, operator: '='}
]
});
});
Photo of Karen Waldschmitt

Karen Waldschmitt, Official Rep

  • 8,260 Points 5k badge 2x thumb
Wow, thanks for sharing your snippets with the community, Oliver and Erik!

Karen