Created
July 24, 2020 02:44
-
-
Save michoelchaikin/404b391a087126690105937bf6e65786 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Usually if you want to access the SuiteScript 2 API via the browser console you need to open specific pages | |
* that load the required libraries (such as a record in edit mode). This script will load the libraries on any | |
* NetSuite page | |
*/ | |
(async () => { | |
/* Add a script element to the DOM and wait until it's loading by checking that | |
a known variable it creates exists */ | |
async function addScriptToDOM(src, scopeToCheck, variableNameToCheck) { | |
const scriptElement = document.createElement("script"); | |
scriptElement.type = 'text/javascript'; | |
scriptElement.src = src; | |
document.body.appendChild(scriptElement); | |
while(! scopeToCheck.hasOwnProperty(variableNameToCheck)) { | |
await new Promise(resolve => setTimeout(resolve, 50)); | |
} | |
}; | |
if(! window.require) { | |
await addScriptToDOM('/javascript/suitescript/lib/NsRequire.js', window, 'require'); | |
await addScriptToDOM('/javascript/suitescript/bootstrap_shared.js', window, 'nlapi'); | |
await addScriptToDOM('/javascript/suitescript/2.0/client/bootstrap.js', require, 'SSModuleLoader'); | |
} | |
require(['N/runtime'], (runtime) => { | |
console.log(`Hello ${runtime.getCurrentUser().name}`); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment