RE: Help render a pdf on a custom record

The search will load – but once I add the record.load line I am getting an error…

Here is script..

/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/

define([‘N/render’,’N/file’,’N/search’,’N/record’],

function(render,file,search,record) {

function execute(scriptContext) {

var recordSearch = search.load({
id : ‘customsearch1673’
});

var searchResult = recordSearch.run().getRange({
start: 0,
end: 10
});

log.debug(‘searchResult’, searchResult);

searchResult.forEach(function(result) {
// Retrieve the internal ID of the record from the search result
var recordId = result.getValue({
name: ‘internalid’
});

// Load the record using the internal ID
var record = record.load({
type: ‘CUSTOMRECORDCOAPRINT’,
id: recordId
});

var templateFile = file.load({
id: ‘131’
});
var renderer = render.create();
renderer.templateContent = templateFile.getContents();
renderer.addRecord({
templateName: ‘record’,
record: record
});

var pdfFile = renderer.renderAsPdf();
pdfFile.name = result.getValue(‘tranid’) + ‘.pdf’; // Set the name of the PDF file to the sales order transaction ID.
pdfFile.folder = 306569; // Replace with the internal ID of the folder where you want to store the PDF files.
pdfFile = pdfFile.save();

// Log the ID of the generated PDF file.
log.debug(‘PDF Generated’, ‘CofA: ‘ + result.getValue(‘tranid’) + ‘, PDF ID: ‘ + pdfFile.id);

// Continue iterating over search results.
return true;
});
}

return {
execute: execute
};
});

happy2be Rookie Asked on February 22, 2023 in SuiteScript.
Add Comment
3 Answers

Cannot call method “load” of undefined – however, I am getting script results in the log.  it just has to do with the record load of the custom record.    I think..

Rookie Answered on February 23, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.