Dumb question. I'm having issues getting my line s...
# suitescript
t
Dumb question. I'm having issues getting my line system note joins to load properly via suitelet script.
/**
* @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
};
});
I've also tried .
html += '<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
});
b
you messed up the join id
t
Thanks @battk, I kinda figured due to the null return values but not sure how that is supposed to be formatted. Like I said, it's a dumb question. 🫠
b
log the columns of the search
t
Seeing as I figure out the join id issue, this is possible?
a
not sure what the reference is to that line system note i'd try join: search.Type.GL_LINES_AUDIT_LOG
alternatively you can just use a columns reference instead of an options object in your getValue method
result.getValue({ searchResult.columns[0] }); result.getValue({ searchResult.columns[1] }); result.getValue({ searchResult.columns[2] }); etc.
well i think 0,1,2 are you SO fields so you can actually leave those alone... and update all the ones with a join to use 3,4,5 etc.
but to battk's points ifyou just do
log.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.
1
t
@Anthony OConnor, doing the log got me the proper Joins and now It's working. Thank you both.
👍 1