Tim Chapman
04/08/2024, 8:04 PMTim Chapman
04/08/2024, 8:05 PM/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/search', 'N/ui/serverWidget', 'N/log'], function(search, serverWidget, log) {
function onRequest(context) {
var salesOrderId = context.request.parameters.salesOrderId;
// Load the saved search and filter by the Sales Order ID
var savedSearch = search.load({ id: 'customsearch_so_line_level_audit_log' });
var filters = savedSearch.filters;
filters.push(search.createFilter({
name: 'internalid',
operator: search.Operator.ANYOF,
values: salesOrderId
}));
savedSearch.filters = filters;
// Run the filtered saved search
var searchResult = savedSearch.run();
// Start building the HTML output
var html = '<!DOCTYPE html>' +
'<html>' +
'<head>' +
'<title>Line Level Audit Log</title>' +
'<style>' +
'table {' +
' border-collapse: separate;' +
' border-spacing: 10px;' +
' width: 100%;' +
'}' +
'th, td {' +
' border: 1px solid black;' +
' padding: 5px;' +
'}' +
'</style>' +
'</head>' +
'<body>' +
'<h1>Line Level Audit Log</h1>' +
'<table>' +
'<tr>' +
'<th>Transaction Date</th>' +
'<th>Document Number</th>' +
'<th>Item</th>' +
'<th>Context</th>' +
'<th>System Note Date</th>' +
'<th>System Note Field</th>' +
'<th>New Value</th>' +
'<th>Old Value</th>' +
'<th>System Note Name</th>' +
'<th>System Note Type</th>' +
'</tr>';
// Process the search results and add them to the HTML output
searchResult.each(function(result) {
var contextValue = result.getValue({ name: 'context', join: 'ln_systemnote' });
log.debug('Context Value', contextValue); // Debugging line
html += '<tr>' +
'<td>' + result.getValue({ name: 'trandate' }) + '</td>' +
'<td>' + result.getValue({ name: 'tranid' }) + '</td>' +
'<td>' + result.getText({ name: 'item' }) + '</td>' +
'<td>' + contextValue + '</td>' +
'<td>' + result.getValue({ name: 'date', join: 'ln_systemnote' }) + '</td>' +
'<td>' + result.getValue({ name: 'field', join: 'ln_systemnote' }) + '</td>' +
'<td>' + result.getValue({ name: 'newvalue', join: 'ln_systemnote' }) + '</td>' +
'<td>' + result.getValue({ name: 'oldvalue', join: 'ln_systemnote' }) + '</td>' +
'<td>' + result.getValue({ name: 'name', join: 'ln_systemnote' }) + '</td>' +
'<td>' + result.getValue({ name: 'type', join: 'ln_systemnote' }) + '</td>' +
'</tr>';
return true; // Continue processing results
});
// Close the HTML tags
html += '</table>' +
'</body>' +
'</html>';
// Write the HTML output to the response
context.response.write(html);
}
return {
onRequest: onRequest
};
});
Tim Chapman
04/08/2024, 8:07 PMhtml += '<tr>' +
'<td>' + result.getValue({ name: 'trandate' }) + '</td>' +
'<td>' + result.getValue({ name: 'number' }) + '</td>' +
'<td>' + result.getText({ name: 'item' }) + '</td>' +
'<td>' + result.getValue({ name: 'ln_systemnote_context' }) + '</td>' +
'<td>' + result.getValue({ name: 'ln_systemnote_date' }) + '</td>' +
'<td>' + result.getValue({ name: 'ln_systemnote_field' }) + '</td>' +
'<td>' + result.getValue({ name: 'ln_systemnote_newvalue' }) + '</td>' +
'<td>' + result.getValue({ name: 'ln_systemnote_oldvalue' }) + '</td>' +
'<td>' + result.getValue({ name: 'ln_systemnote_name' }) + '</td>' +
'<td>' + result.getValue({ name: 'ln_systemnote_type' }) + '</td>' +
'</tr>';
return true; // Continue processing results
});
Tim Chapman
04/08/2024, 8:11 PMbattk
04/08/2024, 8:15 PMTim Chapman
04/08/2024, 8:18 PMbattk
04/08/2024, 8:20 PMTim Chapman
04/08/2024, 9:06 PMAnthony OConnor
04/08/2024, 9:07 PMAnthony OConnor
04/08/2024, 9:11 PMAnthony OConnor
04/08/2024, 9:11 PMAnthony OConnor
04/08/2024, 9:12 PMAnthony OConnor
04/08/2024, 9:16 PMlog.debug('searchcols', savedSearch.columns)
after you load the search it will log out what the actual column references are for you which you can then use correctly in your code.Tim Chapman
04/08/2024, 9:30 PM