Created
November 5, 2011 16:58
-
-
Save nicocrm/1341769 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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