Sorry, I'm not very techy. But is it something like this?
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
/**
* This function generates a PDF for an invoice record and includes data from a saved search
*
* @param {number} invoiceId - The ID of the invoice record to generate the PDF for
* @param {number} searchId - The ID of the saved search to retrieve data from
* @returns {file.File} - The PDF file object
*/
define(['N/render', 'N/search'], function(render, search) {
function generateInvoicePdf(invoiceId, searchId) {
// Load the invoice record
const invoiceRecord = record.load({
type: record.Type.INVOICE,
id: invoiceId
});
// Run the saved search to retrieve charge data for the invoice
const chargeSearch = search.load({
id: '26912'
});
// Add a filter to the saved search to limit results to those related to the invoice record
chargeSearch.filters.push({
name: 'internalid',
operator: 'anyof',
values: [invoiceId]
});
// Execute the saved search and retrieve the results
const chargeSearchResults = chargeSearch.run().getRange({
start: 0,
end: 1000 // limit the number of results returned to 1000
});
// Load the PDF template
const template = file.load({
id: '234', // replace with the ID of your PDF template file
isDynamic: true
}).getContents();
// Create a new renderer and set the template content
const renderer = render.create();
renderer.templateContent = template;
// Add the invoice record and search results to the renderer
renderer.addRecord({ templateName: 'record', record: invoiceRecord });
renderer.addSearchResults({ templateName: 'chargesearch', searchResult: chargeSearchResults });
// Generate the PDF and return the file object
const invoicePdf = renderer.renderAsPdf();
return invoicePdf;
}
return {
onRequest: generateInvoicePdf
};
});