I want to get transaction PDFs out of netsuite via...
# ask-stanley-ai
i
I want to get transaction PDFs out of netsuite via any sort of API. At the moment we are using a RESTlet suitescript using the print transaction PDF function, but this fails when the PDF is beyond 10 MB. Is there any sort of option that bridges this limit?
c
AI generated answer (using internal Slack threads):
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** To get transaction PDFs out of NetSuite via API, you can use the
N/render
module in SuiteScript, specifically the
render.transaction
function. This allows you to download a PDF file directly from a transaction. Here is the link to the official documentation: https://netsuite.custhelp.com/app/answers/detail/a_id/44642 However, if the PDF file size is beyond 10MB, you might encounter issues as you have mentioned. One workaround for this is to generate the PDF and create a link to the file without reading it. This way, you can generate larger PDFs without hitting the limit. Another approach is to use the
ServerResponse.writeFile
function, which might work better for larger files. Here is the link to the official documentation: https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4567633001.html If you want to store the PDF within NetSuite, you can store it in the File Cabinet. However, please note that there might be a limit on the file size. Alternatively, you can use a combination of promise and blob to handle larger files. Here is a sample code snippet:
Copy code
javascript
$ = window.jQuery;
var wurl = window.URL || window.webkitURL;

/* Adding an event listener to the Submit(Print) button */
$('input[type="submit"][value="Print"]').click( function(e) {

    e.preventDefault();
    var oSelectedOrders = getLinesData();
    if (oSelectedOrders.length) {

        var slURL = url.resolveScript(util.extend({}, oSLIDs));
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function() {

            if (this.readyState == 4 && this.status == 200){

                window.open(wurl.createObjectURL(this.response));
            }
        }

        xhr.open('POST', slURL);
        xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
        xhr.responseType = 'blob';
        xhr.send(JSON.stringify(oSelectedOrders));

    }
});
This code adds an event listener to the Submit(Print) button. When clicked, it sends a POST request with the selected orders as the payload. The response is a blob, which is then opened in a new window. Please note that this is not a standard approach and might not work in all cases. Always test thoroughly before implementing in a production environment.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.864013672
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.855346739
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.855285645
Please provide your feedback on this answer.