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

edited April 29, 2020 in Ideas
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); } }});
6
6 votes

Awaiting Review · Last Updated

Comments

  • edited April 29, 2020
    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: '='} ] }); });
  • Karen WaldschmittKaren Waldschmitt 🛠️ 
    edited March 2, 2017
    Wow, thanks for sharing your snippets with the community, Oliver and Erik!

    Karen
  • Arne-Per HeurbergArne-Per Heurberg ✭✭✭✭
    edited March 20, 2020
    does that offer still stand?
  • edited April 29, 2020
    Probably still have the sample page on file, i'll check and see if I can find it 
  • Arne-Per HeurbergArne-Per Heurberg ✭✭✭✭
    edited April 29, 2020
    hi erik, did you happen to find that page?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!