'Netsuite - XML to PDF, CSS question (string of text, but only show starting at character 13)

NetSuite, we have items. I am trying to modify the XML they use to create our Estimate/Invoice PDFS. I have items like this: Pre-Media - Operator Time. We pre-append so that when our teams are creating estimates/invoices the many rates we have group with each other. However we don't want the Pre-Media - part to show. I'd just like it to read Operator Time.

I reviewed a few CSS markups overflow, ::after, but not sure where I should be looking. I do like to do things on my own, but unfortunately I have a timeline :P. It has been a long while since I've played with CSS/HTML and coding in general so I'm re-wetting my feet. Any thoughts? TIA

<tr style="width:100%;">
<td align="left" colspan="15" line-height="150%" rowspan="1" style="width:50%;font-size:9pt;"><#if record.entity == 'Ford CA'>${item.item}<#else>${item.description}</#if></td>
<td align="right" colspan="7" line-height="150%" rowspan="1" style="width:30%;font-size:9pt;">${item.quantity} <span class="uom">${item.units}</span> x ${item.rate}</td><td colspan="26" style="width:20%;align:right;"> ${item.amount}</td>
</tr>

item.item is the field in question. For non-Ford clients, I need to strip the first 12 characters from the item.item. Currently I used the if statement above to cheat until I could figure it out. My Account Service team went live with their new stuff and I had to quickly try to figure out how to get it to work.

I haven't worked on any coding (used to handcode) since 2007/2008, surprised not much has changed, but love the new stuff you can do.



Solution 1:[1]

There are several ways to achieve this, depending on the exact circumstances - the data and the version of Freemarker that's being used are a couple of considerations. I'm not sure what the current version that NetSuite uses is.

Substring

Note: This method is deprecated in later versions of Freemarker.

This can be used to remove a known number of characters from the beginning of a string. If the item codes always start with "Pre-Media - ", you can remove those 12 characters using:

${item.item?substring(12)}

Slicing Expressions

These are preferred over the substring() method from version 2.3.21

Again, if the characters to be removed are always the same length (or alternatively you could wrap it in a conditional expression using <#if><#else></#if>. I won't cover the details of that here.

${item.item[12..]}

Replace

To only remove a specific substring if it exists, you can use the replace method. This should work in any version.

${item.item?replace("Pre-Media - ", "")}

Remove_beginning

Available from version 2.3.21

Best if some items start with a specified string and some don't, provided your Freemarker version is 2.3.21 or better.

${item.item?remove_beginning("Pre-Media - ")}

Keep_after

Available since 2.3.21

If all the items have the pattern of {{prefix}} - {{item}}, you can use keep_after() to remove everything before the " - ". (Also removes the " - ".)

${item.item?keep_after(" - ")}

This is not an exhaustive list of the ways to accomplish this, but it should get you pointed in the right direction.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Krypton