1

I am trying to create an Advanced PDF/HTML template that will display an image using a URL that is in a custom field. The custom field is a hyperlink and the field ID is {custitem_dp_image1}. I am using the image tag and referencing the {custitem_dp_image1} field as the src but I am unable to save the template due to the following error:

java.lang.StringIndexOutOfBoundsException: String index out of range: 0 java.lang.InternalError: java.lang.StringIndexOutOfBoundsException: String index out of range: 0

I've also tried the following code:

<#if result.custitem_dp_image1?length != 0><img src="${result.custitem_dp_image1}" style="width: 100px; height: 100px;" /> </#if>

But I received the following error when I tried to view the Advanced PDF/HTML template from a Saved Search:

The template cannot be saved due to the following errors: org.xml.sax.SAXParseException; lineNumber: 53; columnNumber: 28; The value of attribute "src" associated with an element type "img" must not contain the '<' character.

*The template was stored as invalid.

How can I get this to work and display the image?

5 Answers 5

3

The solution is to change the custom field to type = Free-Form Text and use the following freemarker code:

<#if result.custitem_dp_image1?length != 0><img src="${result.custitem_dp_image1}" style="width: 100px; height: 100px;" /> </#if>
Sign up to request clarification or add additional context in comments.

Comments

0

Instead of Hyperlink use image datatype for your custom field.

2 Comments

Unfortunately that will not work because the images are from another resource outside NetSuite. The images are not hosted on our NetSuite account. We simply use this field to insert the URL of the image.
In that case you can use free form text and put the url there.
0

You can also use a workflow to link the Hyperlink custom field to a Free-Form text field with the Store Value field checked.

Look under SuiteAnswers ID: 89195

Comments

0

The Hyperlink field type will return an entire HTML tag when calling for the field like this: ${result.custitem_dp_image1}

<a href="image_url.jpg">image name</a>

So if you add it to the HTML or tag, it would break because it would look something like this:

<img src="<a href="image_url.jpg">image name</a>">

Freemaker has functions to trim data ?keep_after and ?keep_before So you could use this to bring just the actual URL:

result.custitem_dp_image1?keep_after('href="')?keep_before('"')

In a nutshell, everything after the href=" and everything before the ":

BUT you cant use this inside the "src" tag as it would break the HTML code. You have double quotes inside the Freemaker function and HTML would think the src tag ended at that particular location.

So to circumvent that, I'll insert the code in a variable (either global or assign) and then use just the variable in the SRC tag.

<#global custom_url = result.custitem_dp_image1?keep_after('href="')?keep_before('"')>

<img src="${custom_url}">

Oh, just my 2 cents, Users will likely want to keep the Hyperlink field type as its clickable in the User UI.

Comments

0

You can add @url to the end of the field reference to just get it as text so you can format your own link so for my requirements with the stripe netsuite connector where I want to use the html field with my own text in it I use

<a href="${record.custbody_stripe_payment_link@url}">Pay Now</a>

and your one would be something like this

<#if result.custitem_dp_image1?length != 0><img src="${result.custitem_dp_image1@url}" style="width: 100px; height: 100px;" /> </#if>

Sometimes you just have to wait a few years for the answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.