Printing copy/original (Netsuite) (Issue in advance templet layout)

I have an error when I want to customize the advance template !


/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define([‘N/render’,’N/record’], function(render,record) {

function beforeLoad(context) {
var UserEventType = context.UserEventType;
var contextType = context.type;
var newRecord = context.newRecord;
var newRecordID= context.newRecord.id;
var currentDate = sysDate(); // returns the date
var currentTime = timestamp(); // returns the time stamp in HH:MM:SS
var currentDateAndTime = currentDate + ‘ ‘ + currentTime;

if (contextType == UserEventType.PRINT) {
var fieldId = ‘custbody_first_print’ // fieldId of your custom field / checkbox (or use a datetimestamp)

var isPrinted = newRecord.getValue({ fieldId: fieldId })
if (!isPrinted) {

var myRecord = record.load({id: newRecordID , type: newRecord.type}); // in the beforeLoad, editing the newRecord is not allowed, so you need to load the record first, edit and save.

myRecord.setValue({ fieldId: fieldId, value: currentDateAndTime })
myRecord.save();

}

}
}

function sysDate() {
var date = new Date();
var tdate = date.getDate();
var month = date.getMonth() + 1; // jan = 0
var year = date.getFullYear();
return currentDate = month + ‘/’ + tdate + ‘/’ + year;
}

function timestamp() {
var str = “”;

var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var meridian = “”;
if (hours > 12) {
meridian += “pm”;
} else {
meridian += “am”;
}
if (hours > 12) {

hours = hours – 12;
}
if (minutes < 10) {
minutes = “0” + minutes;
}
if (seconds < 10) {
seconds = “0” + seconds;
}
str += hours + “:” + minutes + “:” + seconds + ” “;

return str + meridian;
}

return {
beforeLoad: beforeLoad,

};
});

 

Error during loading transaction for advanced printing Caused by: com.netsuite.suitescript.exception.NLServerSideScriptException: {“type”:”error.SuiteScriptError”,”name”:”SSS_MISSING_REQD_ARGUMENT”,”message”:”load: Missing a required argument: id”,”stack”:[“createError(N/error)”,”beforeLoad(/SuiteScripts/Copy_Original.js:23)”,”createError(N/error)”],”cause”:{“name”:”SSS_MISSING_REQD_ARGUMENT”,”message”:”load: Missing a required argument: id”},”id”:””,”notifyOff”:false,”userFacing”:true}

Rookie Asked on August 31, 2022 in SuiteScript.
Add Comment
1 Answer(s)

I think you need some logic in case there is no record ID, e.g. new records or when editing PDF templates.

Intermediate Answered on September 5, 2022.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor