Last active
June 11, 2017 23:42
-
-
Save dbischof/fb85f76d589123020359e96fce5c5e40 to your computer and use it in GitHub Desktop.
Set QBO class fields in bulk
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
javascript: (function () { | |
var jsCode = document.createElement('script'); | |
jsCode.setAttribute('src', 'https://rawgit.com/dbischof/fb85f76d589123020359e96fce5c5e40/raw/115a2c0667f9c02a90fc7a1226fb09e08bea96a9/qbo-bulk-class.js'); | |
document.body.appendChild(jsCode); | |
}()); |
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($) { | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function setClassFields() { | |
var wrappers = $('.gridWrapper'); | |
for (var j = 0; j < wrappers.length; j++) { | |
var classFields = $(wrappers[j]).find('.dgrid-row .field-klassId'); | |
var classField; | |
var siblings; | |
for (var i = 0; i < classFields.length; i++) { | |
classField = $(classFields[i]); | |
if (classField.text() != '') { | |
// Skip rows where class is already set | |
continue; | |
} | |
else { | |
siblings = classField.siblings('.field-amount'); | |
if (siblings.length == 0) { | |
siblings = classField.siblings('.field-accountId'); | |
} | |
if (siblings.first().text() == '') { | |
// Skip rows with no amount | |
continue; | |
} | |
} | |
// Make input field editable | |
classField.click(); | |
await sleep(250); | |
// Open drop-down menu | |
dijit.byId($('input[data-qbo-bind="value: klassField"]:visible').attr('id')).loadAndOpenDropDown(); //.openDropDown(); | |
await sleep(250); | |
// Select menu item | |
$('.dijitMenu:visible .dijitMenuItem:not(.dijitMenuNextButton):last').click(); | |
await sleep(500); | |
} | |
// Hide editable content pane before moving on | |
$('input[data-qbo-bind="value: klassField"]:visible').parents('div.dijitContentPane').hide(); | |
}; | |
} | |
setClassFields(); | |
})($); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment