SgtGrarm
SgtGrarm

Reputation: 131

Is it possible to load an image from an image field into a PDF in SuiteScript 2.0

I am currently doing a field lookup for several fields from a parent record and populating the results into a body variable prior to converting to a PDF (xml to pdf) - this works fine but one of the fields is an image field and i can only get the value of the file to populate in the pdf, I am trying to load the image itself so the image displays in the PDF - is this possible?

Upvotes: 2

Views: 2176

Answers (1)

bknights
bknights

Reputation: 15377

So the simple way in your workflow action script would be to take the internalid of the image and use the file api to get the URL:

var fileObj = nlapiLoadFile(id);
imgURLForPDF = fileObj.getURL();

or SS2

//require or define includes N/file
var fileObj = file.load({id:id});
imgURLForPDF = fileObj.url;

But there's also a somewhat odd and undocumented way. When you do an nlapiLookupField call on an image field with the getText parameter set to true you get back the image url instead of the image name. So if you are doing some text lookups on the parent field then you can get your image url in one go:

var valueFields = nlapiLookupField('customrecord_parent', parentId, ['custrecord_simple1', 'custrecord_simple2']);
var textFields = nlapiLookupField('customrecord_parent', parentId, ['custrecord_imagefield', 'custrecord_listfield'], true);
imgURLForPDF = textFields.custrecord_imagefield; //!

The images need to be made available without login. You'll generally have to prefix the values obtained above with your data center url so your freemarker code would look something like:

<img src="https://system.na2.netsuite.com${parentValues.imgURLForPDF}"/>

Upvotes: 3

Related Questions