Skip to content

Instantly share code, notes, and snippets.

@nicocrm
Created November 5, 2011 16:58
Show Gist options
  • Save nicocrm/1341769 to your computer and use it in GitHub Desktop.
Save nicocrm/1341769 to your computer and use it in GitHub Desktop.
function () {
// Execute the "Copy" method on each selected record
var grid = this;
// check that we have a selection
var selectedItems = grid.selection.getSelected();
if (selectedItems.length < 1) {
alert(grid.noSelectionsText);
return;
}
var store = grid.store;
grid.showMessage('Copying widgets...');
var service = Sage.Utility.getSDataService('dynamic');
// this is the actual copy function. It will get called for the first selected item
// then recursively call itself when the business rule invocation completes
var fnCopy = function (i) {
if (store.isItem(selectedItems[i])) {
// business rule invocation
// see https://github.com/SageScottsdalePlatform/SDataJavaScriptClientLib/wiki/How-To-Execute-A-Service-Operation
var request = new Sage.SData.Client.SDataServiceOperationRequest(service)
.setResourceKind('cAccWidgets')
.setOperationName('Copy');
var id = store.getValue(selectedItems[i], "$key");
var entry = {
"$name": "CopyPart",
"request": {
"caccwidgetId": id
}
};
request.execute(entry, {
success: function (result) {
i++;
if (i < selectedItems.length) {
fnCopy(i);
} else {
grid.refresh();
}
},
failure: function (result) {
// ?
}
});
}
};
fnCopy(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment