2

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?

SgtGrarm
  • 131
  • 7
  • Please add some detail about the record types you are using and the script type you are doing the lookups in. The way to do this mayd depend on these – bknights Dec 06 '17 at 15:51
  • Ok, we have 2 custom records - one is the parent of the other. We currently have a workflow action script firing on a button from the child record that does a lookup of an array of fields from the parent (one of which is the image field). and populates them into variables before being converted to a pdf. – SgtGrarm Dec 07 '17 at 08:27

1 Answers1

3

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}"/>
bknights
  • 14,408
  • 2
  • 18
  • 31