RE: Load and Get Values of Custom Transaction Form Record – SuiteScript 2.0
I have a script that I am writing where I want to get the value of the template that is set as the print template on a custom transaction form. I am able to load the custom transaction form record just fine with suitescript.
let formRec = record.load({type: 'custform', id: 175, isDynamic: true});
When I try to get the value of the Print Template field though it just returns back undefined.
The field id is ‘advformlayout’.
I have a Chrome Browser Extension called NetSuite Field Explorer that is able to get the value, so I’m sure there is a way to do it.
Any help would be greatly appreciated.
I suspect you may have moved on, but in case this helps (you or anyone else): I got the same issue as you, however the purpose of getting the template is because I was trying to generate the PDF for my transaction using that specific template, leveraging renderer.setTemplateByScriptId but if you want to generate the PDF for whatever template is associated to the form the transaction is tied to, you can simply use render.transaction.
Here are the 2 methods I created for my needs (try/catch/logging removed for clarity:
function getPOPDFForCustomTemplate(poId, templateScriptId) {
var renderer=render.create();
renderer.setTemplateByScriptId({scriptId:templateScriptId});
renderer.addRecord({templateName:"record",record:record.load({type:record.Type.PURCHASE_ORDER,id:poId})});
return renderer.renderAsPdf();
}
function getPOPDF(poId) {
return render.transaction({entityId:poId,printMode:render.PrintMode.PDF});
}
// And then in my Suitelet, I simply run (with either method):
context.response.writeFile(getPOPDF(poId));
