Check NetSuite’s documentation for “search.Type.” You’ll find a long list of record types searchable by the ‘N/search’ module. Unfortunately, there is at least one missing entry: “scriptexecutionlog”.
Here is a working example in SuiteScript 2.0. Notice, I’m using require() and not define(), so this is ready to paste into debugger. Also, don’t forget to comment out a couple of my filters.
One more note. I looked long and hard to find a way other than reading server logs to see the status of my background scripts. However, I control both Title and Detail fields written by the map() function in the map/reduce scripts in the background. So I can tell my user whatever I choose as they read their log files. The map reduce script can calculate “Percent complete”, or I can just show “Running” until the job ends. Until I find a better way… that’s the plan.
Here is the code in format you can more easily copy.
require([‘N/search’, ‘N/log’],
function (search, log) {
var scriptLog = new Array();
var mySearch = search.create({
type: ‘scriptexecutionlog’,
columns: [
search.createColumn({ name: ‘date’, sort: ‘DESC’ }),
search.createColumn({ name: ‘detail’ }),
search.createColumn({ name: ‘internalid’ }),
search.createColumn({ name: ‘name’, join: ‘script’ }),
search.createColumn({ name: ‘scriptfile’, join: ‘script’ }),
search.createColumn({ name: ‘scriptid’, join: ‘script’ }),
search.createColumn({ name: ‘scripttype’, join: ‘script’}),
search.createColumn({ name: ‘time’ }),
search.createColumn({ name: ‘title’ }),
search.createColumn({ name: ‘user’ }),
],
filters: [
[‘script.name’, ‘startswith’, ‘Logic’],
‘and’,
[‘user’, ‘is’, ‘Kevin McCracken’],
‘and’,
[‘date’, ‘onorafter’, ‘yesterday’],
‘and’,
[‘script.scripttype’, ‘is’, ‘MAPREDUCE’],
]
});
var myPages = mySearch.runPaged({ pageSize: 1000 });
debugger;
for (var i = 0; i < myPages.pageRanges.length; i++) {
var myPage = myPages.fetch({ index: i });
myPage.data.forEach(
function (result) {
var date = result.getValue({ name: ‘date’ });
var detail = result.getValue({ name: ‘detail’ });
var internalid = result.getValue({ name: ‘internalid’ });
var name = result.getValue({ name: ‘name’, join: ‘script’ });
var scriptfile = result.getValue({ name: ‘scriptfile’, join: ‘script’ });
var scriptid = result.getValue({ name: ‘scriptid’, join: ‘script’ });
var scripttype = result.getValue({ name: ‘scripttype’, join: ‘script’ });
var time = result.getValue({ name: ‘time’ });
var title = result.getValue({ name: ‘title’ });
var user = result.getValue({ name: ‘user’ });
objEntry = {
date: date,
detail: detail,
internalid: internalid,
name: name,
scriptfile: scriptfile,
scriptid: scriptid,
scripttype: scripttype,
time: time,
title: title,
user: user
};
log.debug(JSON.stringify(objEntry));
debugger;
scriptLog.push(objEntry);
}
)
}
}
)