finding NetSuite form scriptids
by Gerald Gillespie
JavaScript
(({
start,
end,
targetScriptid,
concurrency,
timeLimit,
abortOnSuccess = true
}, $) => {
if (!/netsuite.com$/.test(window.location.origin)) {
alert('You need to be on a netsuite URL (and logged in)')
return;
}
//efficient registry
const summary = new Map();
const urls = [
Object.assign({}, window.location, {
id: '&id=',
xml: '?xml=T',
pathname: '/app/common/custom/custform.nl'
}),
Object.assign({}, window.location, {
id: '&id=',
xml: '?xml=T',
pathname: '/app/common/custom/custentryform.nl'
})
];
//Todo: handle all urls entries
const urlParts = urls[0];
//cast target to a regex
const targetRgx = targetScriptid instanceof RegExp ? targetScriptid : new RegExp(targetScriptid.toLowerCase());
//cast concurrency to an integer
concurrency = typeof concurrency === 'undefined' || isNaN(parseInt(concurrency)) ? 0 : parseInt(concurrency);
//escape flag
let abort = false;
//timemaximum
timeLimit = typeof timeLimit === 'undefined' || isNaN(parseInt(timeLimit)) ? 0 : parseInt(timeLimit);
if (timeLimit > 0)
setTimeout(() => {
if (abort)
return
tryAbort({
abort: true,
msg: `Your attempt timed out after ${timeLimit} seconds`
});
}, timeLimit * 1000)
const counters = {
start: start,
end: end,
current: null,
clockStart: (new Date().getTime()) / 1000,
clockEnd: null
}
const tryAbort = ({
abort,
msg
}) => {
if (abort === false)
return
abort = true;
console.log(msg);
console.log('Summary');
for (let [key, value] of summary.entries()) {
console.log(key, value);
}
}
//handle http response and match target pattern or discard
const processResponse =...