Adam Weaver
02/20/2025, 3:43 PM/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/search'], function(search) {
function onRequest(context) {
if (context.request.method === 'GET') {
try {
var savedSearchId = '2953'; // Replace with your actual Saved Search ID
var savedSearch = search.load({ id: savedSearchId });
var resultSet = savedSearch.run();
var results = resultSet.getRange({ start: 0, end: 50 }); // Adjust range as needed
var html = 'htmlhead';
html += 'style';
html += 'body { font-family: Arial, sans-serif; }';
html += 'table { width: 100%; border-collapse: collapse; }';
html += 'th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }';
html += 'th { background-color: #f2f2f2; }';
html += '.progress { overflow: hidden; height: 18px; background-color: #ccc; border-radius: 4px; box-shadow: inset 0 1px 2px rgba(0,0,0,0.1); }';
html += '.progress-bar { height: 100%; font-size: 11px; line-height: 18px; color: #fff; text-align: center; background-color: #428bca; box-shadow: inset 0 -1px 0 rgba(0,0,0,0.15); transition: width .6s ease; }';
html += '/style';
html += '/headbody';
html += 'h2WO Daily Plan Results/h2';
html += 'table';
html += 'tr';
if (results.length > 0) {
var columns = results[0].columns;
// **Generate Table Headers**
columns.forEach(function(column) {
html += 'th' + column.label + '/th';
});
html += '/tr';
// **Generate Table Rows**
results.forEach(function(result) {
html += 'tr';
columns.forEach(function(column) {
var value = result.getValue(column);
// **Handle non-string values (fix for the error)**
if (typeof value === 'object' && value !== null) {
value = result.getText(column) || '[Object]'; // Use getText() for objects
} else {
value = value !== null && value !== undefined ? String(value) : ''; // Convert everything to a string
}
// **Detect and render Progress Bar**
if (typeof value === 'string' && value.includes('%')) {
var percentage = parseFloat(value.replace('%', '')) || 0;
html += 'tddiv class="progress"div class="progress-bar" style="width:' + percentage + '%;"' + percentage + '%/div/div/td';
} else {
html += 'td' + value + '/td';
}
});
html += '/tr';
});
html += '/table';
} else {
html += 'pNo results found./p';
}
html += '/body/html';
context.response.write(html);
} catch (e) {
context.response.write('Error: ' + e.message);
}
}
}
return {
onRequest: onRequest
};
});Anthony OConnor
02/20/2025, 4:19 PMif (typeof value === 'string' && value.includes('%')) {Anthony OConnor
02/20/2025, 4:20 PMAnthony OConnor
02/20/2025, 4:24 PMAnthony OConnor
02/20/2025, 4:25 PMAnthony OConnor
02/20/2025, 4:26 PMAdam Weaver
02/20/2025, 4:34 PMAnthony OConnor
02/20/2025, 4:36 PMAnthony OConnor
02/20/2025, 4:36 PMAnthony OConnor
02/20/2025, 4:37 PMvalue = value !== null && value !== undefined ? String(value) : ''; // Convert everything to a stringAdam Weaver
02/20/2025, 4:37 PMAdam Weaver
02/20/2025, 4:37 PMerictgrubaugh
02/20/2025, 5:52 PMincludes is not a method on the String prototype in SuiteScript 2.0 (ES5). You'll need to switch your script to 2.1, first by specifying the @NApiVersion correctly, then likely by re-creating the Script record.Adam Weaver
02/20/2025, 6:04 PMAdam Weaver
02/20/2025, 6:29 PMerictgrubaugh
02/20/2025, 8:08 PM