Skip to content

Instantly share code, notes, and snippets.

@rickcnagy
Last active August 29, 2015 13:57
Show Gist options
  • Save rickcnagy/9793404 to your computer and use it in GitHub Desktop.
Save rickcnagy/9793404 to your computer and use it in GitHub Desktop.
Opens and saves a list of records in an Aura DataTable, such as students in the Students module, report cards in the Report Cards module, transcripts, etc. Fork as necessary for specific locales.
//
// OpenAndSaveRecords.js
// Rick Nagy
// 2014-03-26
//
// run via js console
function init() {
stopAsap = false;
$(window).keypress(function(e) {
if (e.which === 3) {
stopAsap = true;
}
});
openRecord($( ".dataTableContentRow" ).eq(getStart() - 1));
}
function getStart() {
var startRow = prompt('Starting row?', '1');
if (startRow === null) quit();
return parseInt(startRow);
}
function nextRecord(row) {
openRecord(row.next());
}
function openRecord(row) {
if (validRow(row)) {
row.children( ":last" ).click();
afterLoad(interactWithRecord, row);
} else {
nextRecord(row);
}
}
function validRow(row) {
return true;
}
function interactWithRecord(row) {
// interact with record
saveAndClose(row);
}
function saveAndClose(row) {
$( "button:contains('Save & Close')" ).click();
afterLoad(nextRecord, row);
}
function close(row) {
$( ".demotedButtonWidget:contains(Close)" ).click();
afterLoad(nextRecord, row);
}
function quit() {
while ($( "*:contains('Close')" ).length > 0) {
$( "*:contains('Close'):last" ).click();
}
throw new Error('Aborted JS');
}
function afterLoad(callback, param) {
if (stopAsap) quit();
else {
var loading = setInterval(function() {
if ($( "*[class^='load']:not('.ribbonSelectorWidget *'):visible" ).length === 0) {
clearInterval(loading);
callback(param);
}
}, 10, param);
}
}
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment