Hello,
I'm trying to run a script for some reason is not working. I'm following the instructions from SuiteAnswer: ID 49137 - but so far, I'm not getting anything on the form, but also, I'm not getting any errors.
This is the script I have:
http:///**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(['N/record', 'N/search', 'N/ui/serverWidget'], function (record, search, serverWidget) {
function beforeLoad(scriptContext) {
try {
if (scriptContext.type == 'print') {
var currentRec = scriptContext.newRecord;
var recid = currentRec.id;
columns[0] = search.createColumn({
name: "item",
join: "item",
sort: search.Sort.ASC,
label: "Name"
});
columns[1] = search.createColumn({
name: "itemid",
join: "item",
label: "Internal ID"
});
columns[2] = search.createColumn({
name: "serialnumber",
join: "item",
label: "Serial Number"
});
columns[3] = search.createColumn({
name: "expirationdate",
label: "Expiration Date"
});
//Creating search to get all the values for work order
var mySearch = search.create({
type: "inventorydetail",
filters:
[
["expirationdate", "isnotempty"]
],
columns: columns
});
var searchResultCount = mySearch.runPaged().count;
mySearch.run().each(function (result) {
// .run().each has a limit of 4,000 results
results.push(result);
return true;
});
//populate current printout with custom record entries
var customRecords = { columns: columns, results: results };
var columns = customRecords.columns, results = customRecords.results;
var custrecord = scriptContext.form.addField({ id: 'custpage_custrecord_to_print', type: serverWidget.FieldType.LONGTEXT, label: " " }),
custrecordArray = [];
if (results && results instanceof Array) {
for (var i = 0; i < results.length; i++) {
var singleLine = {};
for (var j = 0; j < columns.length; j++) {
if (i == i && j == 2) {
var value = results[i].getText(columns[j]);
} else {
var value = results[i].getValue(columns[j]);
}
if (j == 0 || j == 1 || j == 2) {
if (value.indexOf('.') == 0 || value.indexOf(',') == 0 || value.indexOf('-.') == 0 || value.indexOf('-,') == 0) {
value = '0' + value;
}
}
singleLine["col" + j] = (value) ? value : '';
}
custrecordArray.push(singleLine);
}
custrecord.defaultValue = JSON.stringify(custrecordArray);
}
}
} catch (e) {
log.error("ERROR", e);
}
}
return {
beforeLoad: beforeLoad,
};
});
and the pdf code added to the Item fulfillment pdf form is:
<#if record.custpage_custrecord_to_print?has_content>
<#assign customrecord = record.custpage_custrecord_to_print?eval />
<table style="page-break-inside: avoid; width: 100%; margin-top: 10px;">
<thead>
<tr>
<th align="left" colspan="5" style="padding: 10px 6px;">column 1</th>
<th align="left" colspan="5" style="padding: 10px 6px;">column 2</th>
<th align="left" colspan="5" style="padding: 10px 6px;">column 3</th>
<th align="left" colspan="5" style="padding: 10px 6px;">column 4</th>
</tr>
</thead>
<#list customrecord as customrecord_line>
<tr>
<td align="left" colspan="5">${customrecord_line.col0}</td>
<td align="left" colspan="5">${customrecord_line.col1}</td>
<td align="left" colspan="5">${customrecord_line.col2}</td>
<td align="left" colspan="5">${customrecord_line.col3}</td>
</tr>
</#list>
</table>
</#if>
I just want to say that I'm new to scripting - so, I'm pretty sure i made some mistakes on my code that I cannot detect.
I appreciate any help you can give me regarding this.