This topic contains 2 replies, has 0 voices, and was last updated by michoel 7 years, 9 months ago.

  • Author
    Posts
  • #2259

    rporteous

    Hi,

    I’m using Advanced PDF/HTML transaction forms and trying to get the “First Name” of a contact on a transaction…

    I can get the full name of the primary contact ${record.entity.contact} which gives me firstname and lastname…

    I tried using ${record.entity.contact.firstname} but no luck… So over to the freemarker manual and I found the ?keep_before command.

    So I tried this ${record.entity.contact?keep_before(” “)} thinking this might work… But alas, I am no programmer…

    Any suggestions to get the first name for a primary contact for an transaction (estimate)?

    Thanks

    Russ
    This is a cached copy. Click here to see the original post.

  • #2260

    michoel

    The “?keep_before” built-in was only added to Freemarker version 2.3.21. Netsuite is still using an older version of the library (I believe 2.3.19).

    As an alternative you can try something like the below –

    Code:
    ${record.entity.contact?substring(0, record.entity.contact?index_of(” “))}


    rporteous replied on 02/08/2017, 08:36 PM: Thanks Michoel,

    Unfortunately NS gave me this error during code validation…

    The template cannot be saved due to the following errors:

    Exception during template merging.

    com.netledger.templates.TemplateServiceException: Exception during template merging.

    java.lang.StringIndexOutOfBoundsException: String index out of range: -1

    Any suggestions? My hunch is that “?substring” is deprecated…

    Russ

  • #2261

    michoel

    Hey Russ,

    That error is if there is no space in the contact name, so ?index_of returns -1.

    Here’s a revised version that checks for this.

    You are correct about ?substring being deprecated, so I’ve updated with the code to use “slicing expressions” instead (though I don’t think that was the cause of the above error).

    Code:

    ${record.entity.contact[0..pos-1]}

You must be logged in to reply to this topic.