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


function(render,file,search,record) {

function execute(scriptContext) {

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

var searchResult ={
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({
id: recordId

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

var pdfFile = renderer.renderAsPdf(); = 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 =;

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

// Continue iterating over search results.
return true;

return {
execute: execute

Rookie Asked on February 22, 2023 in SuiteScript.
Add Comment
3 Answer(s)


What is the error?



Intermediate Answered on February 23, 2023.
Add Comment

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

You need to avoid:

var record = record…

Pick a different variable name.

Intermediate Answered on February 23, 2023.

thank you.. that was it.. now on to the next error!

on February 24, 2023.
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   Become a Sponsor   Become a Sponsor