I'm trying to splice a string in Netsuite Advanced PDF using Freemarker. I've read the documentation for string builtins, and wasn't sure how this is possible.
I have a table that's supposed to include a freetext variable. I want the text to spill over to the next td if it's too long, but I don't know if that's even doable. I thought I could try to splice half the string if it's a certain amount of characters, and then place the second part of it into the next td. Doing this produces an error when generating the PDF that the range is out of bounds.
Is what I'm trying to do even possible or am I going about it the wrong way? Relevant code below.
<td style="background-color:#dce6f1" colspan="4"><strong>Additional Items:</strong>${record.custbody387[0..*50]}</td>
</tr>
<tr>
<td colspan="4">${record.custbody387[51..*100]}</td>
</tr>
<tr>
<td colspan="4" style="background-color:#dce6f1">This is Note 3</td>
</tr>
<tr>
You could simply use an #if
or ?then
in the second td
to dodge the case that causes error. Getting a slice (of predefined size) can also be generalized into a function (or into a macro, but a function is more fitting for this), but if you call it only twice, it's probably an overkill:
<#function getSlice(s, partNo)>
<#local start = 50 * (partNo - 1)>
<#return (s?length <= start)?then("", s[start..*50])>
</#function>
<tr>
<td style="background-color:#dce6f1" colspan="4"><strong>Additional Items:</strong>
${getSlice(record.custbody387, 1)}
</td>
</tr>
<tr>
<td colspan="4">
${getSlice(record.custbody387, 2)}
</td>
</tr>