This provides a scripting solution to find text from Files using SuiteScript:
var searchText = 'Lorem ipsum';
var files = nlapiSearchGlobal('File: %.txt');
var fileId = files[i].getId();
try {
var file = nlapiLoadFile(fileId);
var index = file.getValue().toLowerCase().indexOf(searchText.toLowerCase());
nlapiLogExecution('DEBUG', 'Text ' + (index > 0 ? 'FOUND' : 'NOT found') + ' on File ' + file.getName() + ' (' + fileId + ')');
} catch(e) {
nlapiLogExecution( 'DEBUG', 'ERROR While loading File ID: ' + fileId, (e instanceof nlobjError ? e.getCode() + '<br />' + e.getDetails() : e.toString()) );
}
}
On Line 2 of the code, indicates to search for files having .txt as the extension name. This can be changed to .csv, .html, etc. depending on what is needed.
It can be run on any server-side scripts, but it is best to use it on Scheduled Scripts to avoid governance exceeded errors.
Execution Logs shows if the text is found or not in the file on the for loop.
No comments:
Post a Comment