Reputation: 150
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?
Upvotes: 1
Views: 5543
Reputation: 1
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.
Upvotes: 0
Reputation: 3
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
Upvotes: 0
Reputation: 150
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>
Upvotes: 2