RE: How to bulk export all PDF’s from NetSuite

Hi

Is anyone aware of how to do a bulk full export of all PDF’s from NetSuite? 

Zaahidp Rookie Asked on March 1, 2023 in How To's.
Add Comment
4 Answers

The exportPDFInvoices() function defines a search to find all Customer and Vendor PDF invoices in NetSuite. It then loops through the search results and saves down each PDF file internally. You can schedule this script to run automatically on a recurring basis using the NetSuite Scheduled Script feature.

Note that you will need to replace the 123 placeholder in the script with the internal ID of the folder where you want to save the files.

 

/**
* The main function that exports and saves down PDF invoices.
*/
function exportPDFInvoices() {
// Define the search filters to find invoices
var filters = [
search.createFilter({
name: ‘mainline’,
operator: search.Operator.IS,
values: [‘T’]
}),
search.createFilter({
name: ‘type’,
operator: search.Operator.ANYOF,
values: [‘CustInvc’, ‘VendBill’]
})
];

// Define the search columns to retrieve
var columns = [
search.createColumn({
name: ‘tranid’
}),
search.createColumn({
name: ‘tranid’,
join: ‘customer’
}),
search.createColumn({
name: ‘tranid’,
join: ‘vendor’
}),
search.createColumn({
name: ‘transactionnumber’
}),
search.createColumn({
name: ‘pdftransaction’,
join: ‘file’
})
];

// Create the search object and run the search
var searchObj = search.create({
type: search.Type.TRANSACTION,
filters: filters,
columns: columns
});
var searchResult = searchObj.run().getRange({
start: 0,
end: 1000
});

// Loop through the search results and save each PDF file
for (var i = 0; i < searchResult.length; i++) {
var result = searchResult[i];

// Get the transaction ID, customer name, vendor name, and PDF file object
var transactionId = result.getValue(‘tranid’);
var customerName = result.getText(‘customer’);
var vendorName = result.getText(‘vendor’);
var pdfFile = result.getValue({
name: ‘pdftransaction’,
join: ‘file’
});

// Save down the PDF file internally
if (pdfFile) {
var fileObj = file.load({
id: pdfFile
});
fileObj.name = transactionId + ‘.pdf’;
fileObj.folder = 123; // Replace with the internal ID of the folder where you want to save the files
fileObj.save();
}
}
}

Rookie Answered on March 2, 2023.

This script just moves and renames existing attached PDFs.

on March 2, 2023.
Add Comment

Your Answer

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