Handlebars helper reference

Comments

70 comments

  • Harish Bakka
    Engaged

    Thanks, Stephen, it worked. will post if I have any issues.

     
    0
  • Steve Klett Strategic Partner
    Celigo University Level 4: Legendary
    Answer Pro
    Great Answer
    Top Contributor
    Awesome Follow-up
    Engaged

    I have a use case where I need to define a JSON array by nested enumeration of hierarchical source data. The challenge is how to avoid the trailing comma for the last element.

    [
    3,
    6, <-- Err!
    ]

    Because the source data is hierarchical, I can't make the comma conditional on the outer #each and likewise I can't make it conditional on the nested, inner #each; I need to consider BOTH of them when determining if a comma should be created or not.

    Were it not for the inability to access the @last variable in the parent scope, something like this would work perfect:

    [
    {{#each outer_array}}
    {
    "name": "foo {{{name}}}"
    },{{#each inner_array}}{
    "size": {{{size}}}
    }{{#unless @last && ../@last}},{{/unless}}
    {{/each}}
    {{/each}}
    ]

    The key is checking for the end of the outer and inner loops.

    {{#unless @last && ../@last}},{{/unless}}

    The problem is, ../@last doesn't work. I can't find any way to access @ variables from the inner loop scope.


    UPDATED 6/17/2021 –
    Solved, self-answered:

    The @ symbol precedes the path: 

    {{{@../index}}}
    • Celigo action item: update @last with example for nested loops
    0
  • Courtney Jordan Experience Strategy & Design Director Community moderator
    Celigo University Level 4: Legendary
    Awesome Follow-up
    Top Contributor

    Hi Dominik Antalík,

    Thanks for letting us know about your use case. I apologize for the late response - I missed this comment coming in. Have you gotten this resolved yet? I'm checking with our handlebars experts.

    0
  • Courtney Jordan Experience Strategy & Design Director Community moderator
    Celigo University Level 4: Legendary
    Awesome Follow-up
    Top Contributor

    Hi Dominik Antalík,

    We do not support registering custom helpers at this time. If you could enter an enhancement request, we can gauge whether to add this to the roadmap. Thanks!

    0
  • A Arora

    HI,

    If we have an array of objects:

    [{amount: 10,...}, {amount:20,...}, {amount:20,...}]

    How can we add all amount field from each object then multiply by 100 using handlebar expressions?

    0
  • Stephen Brandt Documentation Manager Community moderator
    Celigo University Level 4: Legendary
    Engaged
    Great Answer
    Top Contributor

    Hi, A Arora. Thanks for contacting us, and sorry for the delay over the long U.S. holiday weekend. 

    A few suggestions are posted in a related Community thread. The easiest, according to the in-house experts would be to transform the data structure to flatten the amounts into a single array. Then, you can call sum as follows:

    {{multiply (sum amount)  100}}

    You should consider the other solutions in the linked post if you needed to maintain your present record structure for downstream processing. 

    0
  • Steve Klett Strategic Partner
    Celigo University Level 4: Legendary
    Answer Pro
    Great Answer
    Top Contributor
    Awesome Follow-up
    Engaged

    timestamp should be updated to indicate that when no format is supplied it will return an ISO8601 string (what I wanted). I had to go dig through moment.js docs to determine that for sure.

    0
  • Steve Klett Strategic Partner
    Celigo University Level 4: Legendary
    Answer Pro
    Great Answer
    Top Contributor
    Awesome Follow-up
    Engaged

    On the dateFormat documentation for i/pformat:

    This field is the date object referenced in the Context.

    Whaaaaa? ;)

     

    0
  • Tom Santiago Principal Technical Writer Community moderator
    Engaged
    Top Contributor
    Celigo University Level 4: Legendary

    Steve Klett 

    Thanks for this information regarding the default timestamp format. I've revised the article to reflect your research. 

    For the dateFormat question, we use the term "Context" to refer to the source data from the incoming record to be interpreted by the handlebars expression, so the following statement:

    "This field is the date object referenced in the Context."

    a few lines down from that we state:

    "Input format (i/pformat) is where you define the "input" format contained in the Context file"

    So if you have an incoming record with a specific format, you would specify the incoming format as the i/pformat. You would then use the o/pformat to define the format that you want to convert the incoming format into. 

    Does that make more sense? Please email me at tom.santiago@celigo.com if you'd like to further discuss how I can improve the documentation so that it's less confusing.

    0
  • Steve Klett Strategic Partner
    Celigo University Level 4: Legendary
    Answer Pro
    Great Answer
    Top Contributor
    Awesome Follow-up
    Engaged

    Hi,

    The regexMatch documentation doesn't make any sense to me. The property description for regex is wrong:

    regex: the new value which will replace the existing value.

    The first two samples seem to have the syntax for regexReplace, not to mention the second one is maybe not a great example to replace a value with the same value. Anyway, I had to spend quite a bit of time looking at this trying to figure out if I'm dense and need a break of if the docs are totally confusing me.

    0
  • Josyrley de Almeida

    Hi,
    I have this to get the current date
                     {{dateFormat "YYYY-MM-DD HH:mm" date}}
    I'd like to add the timezone (Europe/London).

    I tried this {{dateFormat "YYYY-MM-DD HH:mm" date "YYYY-MM-DD[T]hh:mm:ss.sss[Z]" "Europe/London"}} but I got the error

    "Could not compile handle bar \{{dateFormat "YYYY-MM-DD HH:mm" date "YYYY-MM-DD[T]hh:mm:ss.sss[Z]" "Europe/London"}}\" because \"handlebars Helper {{dateFormat}} expects date argument when you have i/p date format\" .Please correct and retry"

    How can I add the timezone when getting the current date?

    Thank you.
    Josy

    0
  • Kate Larson Senior UX Researcher Community moderator

    Hi Josyrley de Almeida -
    I checked in with one of our handlebars gurus and this was his response:
    If you don't specify an input date format (it's often not required), you can use a blank string for it when adding timezone. In a handlebar w/out timezone, the blank string is assumed.

    {{dateFormat "YYYY-MM-DD HH:mm" date "" "Europe/London"}}

    In order for

    {{dateFormat "YYYY-MM-DD HH:mm" date "YYYY-MM-DD[T]hh:mm:ss.sss[Z]" "Europe/London"}} 

    to work, there would need to be a source field "date" in YYYY-MM-DD[T]hh:mm:ss.sss[Z]" format. Also, I don't think brackets around the [T] and [Z] are correct, even if there is that field.

    YYYY-MM-DDTHH:mm:ssZ

    If you need any further assistance, please sign up for an office hours session. Thanks!

    0
  • Stephen Lemp

    What is the proper syntax for the {{else_if}} block?

    0
  • Tom Santiago Principal Technical Writer Community moderator
    Engaged
    Top Contributor
    Celigo University Level 4: Legendary

    Hi Stephen Lemp,

    Here is an example of  {{else if}}:

    {{#if name}}{{name}}{{else if test}}Steve{{else}}Kat{{/if}}

    In the above example, if the name field exists, the value of name prints.

    If the name field does not exist {{else if}}, and a field named test exists, then Steve prints.

    If neither name nor test fields exist, Kat prints.

    We'll revise this section of the article for clarity soon.

    0
  • Brian Brown

    Any recommendations on how to dateAdd to get the previous month?  1 month previous to today that is.

    All we really care about is 'MON-YYYY' format.

    Thanks!

    0
  • Permanently deleted user NetSuite Integration Whiz Strategic Support Lead
    Celigo University Level 4: Legendary

    Hi Brian,

    Assuming that your input date is something like "2021-12", the following should work:

    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Jan"}}{{dateFormat "[Dec]-YYYY" (dateAdd [Order Date] "-31556952000")}}{{else}}{{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Feb"}}{{dateFormat "[Jan]-YYYY" [Order Date]}}{{else}}{{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Mar"}}{{dateFormat "[Feb]-YYYY" [Order Date]}}{{else}}{{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Apr"}}{{dateFormat "[Mar]-YYYY" [Order Date]}}{{else}}{{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "May"}}{{dateFormat "[Apr]-YYYY" [Order Date]}}{{else}}{{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Jun"}}{{dateFormat "[May]-YYYY" [Order Date]}}{{else}}{{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Jul"}}{{dateFormat "[Jun]-YYYY" [Order Date]}}{{else}}{{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Aug"}}{{dateFormat "[Jul]-YYYY" [Order Date]}}{{else}}{{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Sep"}}{{dateFormat "[Aug]-YYYY" [Order Date]}}{{else}}{{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Oct"}}{{dateFormat "[Sep]-YYYY" [Order Date]}}{{else}}{{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Nov"}}{{dateFormat "[Oct]-YYYY" [Order Date]}}{{else}}{{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Dec"}}{{dateFormat "[Nov]-YYYY" [Order Date]}}{{else}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}

    If your input date is in a different format, you'll just need to change "YYYY-MM" (the input dateFormat) to the proper format.

    Additionally, the above assumes that the field is named "Order Date" in your source data.

    Here's a version of the above code block that should be a bit easier to read, but you'll want to use the one above in your integration:

    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Jan"}}
    {{dateFormat "[Dec]-YYYY" (dateAdd [Order Date] "-31556952000")}}
    {{else}}
    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Feb"}}
    {{dateFormat "[Jan]-YYYY" [Order Date]}}
    {{else}}
    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Mar"}}
    {{dateFormat "[Feb]-YYYY" [Order Date]}}
    {{else}}
    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Apr"}}
    {{dateFormat "[Mar]-YYYY" [Order Date]}}
    {{else}}
    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "May"}}
    {{dateFormat "[Apr]-YYYY" [Order Date]}}
    {{else}}
    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Jun"}}
    {{dateFormat "[May]-YYYY" [Order Date]}}
    {{else}}
    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Jul"}}
    {{dateFormat "[Jun]-YYYY" [Order Date]}}
    {{else}}
    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Aug"}}
    {{dateFormat "[Jul]-YYYY" [Order Date]}}
    {{else}}
    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Sep"}}
    {{dateFormat "[Aug]-YYYY" [Order Date]}}
    {{else}}
    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Oct"}}
    {{dateFormat "[Sep]-YYYY" [Order Date]}}
    {{else}}
    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Nov"}}
    {{dateFormat "[Oct]-YYYY" [Order Date]}}
    {{else}}
    {{#contains (dateFormat "YYYY-MMM" [Order Date] "YYYY-MM") "Dec"}}
    {{dateFormat "[Nov]-YYYY" [Order Date]}}
    {{else}}
    {{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}{{/contains}}}

    Dan

    0
  • Brian Brown

    Thanks @....  Looks like that formula is exceeding the maximum byte size of the FILE NAME field though.  We're looking to use this handlebar expression to provide the file name in an FTP operation.

    No way to actually addMonth ?  

    Moment.js does offer a way to addMonth.  And from what I understand Celigo uses moment.js on the backend.

    No way to make an addMonth call in handlebars at all huh?

    Thanks for your input on this!

     

    0
  • Permanently deleted user NetSuite Integration Whiz Strategic Support Lead
    Celigo University Level 4: Legendary

    Hi Brian,

    Ah, I didn't realize this was for an FTP filename.

    We do not have a handlebar helper for addMonth, however, please feel free to file an enhancement request here.

    An alternative would be the following:

    {{dateFormat "MMM-YYYY" (dateAdd [Order Date] "-2592000000")}}

    The above can be inaccurate, as it subtracts 2592000000 milliseconds (30 days) from the given timestamp. For instance, if the "Order Date" is 2021-03-01, the output would be "Jan-2021, since February only has 28 (or 29) days.

    Another alternative would be if you can include the date with the previous month in your export data, you can reference this field in your filename.

    Best Regards,
    Dan

    0
  • Permanently deleted user NetSuite Integration Whiz Strategic Support Lead
    Celigo University Level 4: Legendary

    Hi Brian,

    I had a little more time to clean up that first handlebar helper and created one that uses the current timestamp then changes that value to the prior month (and year, for dates in January). This should do the trick:

    {{#contains (dateFormat "MMM") "Jan"}}{{dateFormat "[Dec]-YYYY" (dateAdd "-31556952000")}}{{else contains (dateFormat "MMM") "Feb"}}{{dateFormat "[Jan]-YYYY"}}{{else contains (dateFormat "MMM") "Mar"}}{{dateFormat "[Feb]-YYYY"}}{{else contains (dateFormat "MMM") "Apr"}}{{dateFormat "[Mar]-YYYY"}}{{else contains (dateFormat "MMM") "May"}}{{dateFormat "[Apr]-YYYY"}}{{else contains (dateFormat "MMM") "Jun"}}{{dateFormat "[May]-YYYY"}}{{else contains (dateFormat "MMM") "Jul"}}{{dateFormat "[Jun]-YYYY"}}{{else contains (dateFormat "MMM") "Aug"}}{{dateFormat "[Jul]-YYYY"}}{{else contains (dateFormat "MMM") "Sep"}}{{dateFormat "[Aug]-YYYY"}}{{else contains (dateFormat "MMM") "Oct"}}{{dateFormat "[Sep]-YYYY"}}{{else contains (dateFormat "MMM") "Nov"}}{{dateFormat "[Oct]-YYYY"}}{{else contains (dateFormat "MMM") "Dec"}}{{dateFormat "[Nov]-YYYY"}}{{/contains}}

    Here it is in action:


    Dan

    0
  • Permanently deleted user NetSuite Integration Whiz Strategic Support Lead
    Celigo University Level 4: Legendary

    Hi Brian,

    One of our engineers, Lucian Hymer, came up with a more elegant solution:

    {{#compare (dateFormat "MM") "==" 1}}Dec-{{subtract (dateFormat "YYYY") 1}}{{else}}{{dateFormat "MMM" (subtract (dateFormat "MM") "1") "MM"}}-{{dateFormat "YYYY"}}{{/compare}}

    This will give the same output as well:

    Dan

    0
  • Brian Brown

    Hey Dan, awesome!  This is great and is working wonderfully!  Really appreciate this quick response and great solution.  Thanks Dan!

    0
  • Mel Haynes, Jr.

    This may be a small thing, but would it be possible to add a "Back To Top" button? Often times Im here and looking something up,then need to go back up to the top to look at another function. I know I can click the "Back" button, but thats so far up on the screen!! (im joking about that). Just one of those simple quality of life things for those like me that have to spend time here

    0
  • Tom Santiago Principal Technical Writer Community moderator
    Engaged
    Top Contributor
    Celigo University Level 4: Legendary

    Hi Mel Haynes, Jr.,

    We are considering some solutions to the problem you've raised including a back to top button or a side nav menu, but we haven't yet confirmed upcoming revisions to our knowledgebase navigation strategy. We will notify everyone when such improvements are rolled out. One trick I rely on at the moment is right-clicking the link and opening it in a new tab to create a browser instance open to each handlebars expression I need to reference. 

    Tom

    0
  • Steve Klett Strategic Partner
    Celigo University Level 4: Legendary
    Answer Pro
    Great Answer
    Top Contributor
    Awesome Follow-up
    Engaged

    Mel Haynes, Jr. CTRL+HOME will jump back to the top.

    1
  • Tom Santiago Principal Technical Writer Community moderator
    Engaged
    Top Contributor
    Celigo University Level 4: Legendary

    Thanks for the tip, Steve Klett. I added that trick to the top of this article.

    Tom

    0
  • AJ Nielsen

    I'm trying to use the {{capitalizeAll Field}} expression to capitalize First and Last Names from on online form to normalize the data before it is imported in to NetSuite and it's not working. 

    Template - {{capitalizeAll 86}}

    Context - '86' is the Field ID on the form for First Name

    Output - ""

    Without the expression I get the name imported exactly as it was input. "FIRST name = FIRST name" and I would like to get "First Name" But with the expression no data comes through and I get an error stating missing data for import field "First name"

    I've tried {{capitalizeAll ID.86}} and other versions showing the path but the error comes back:

    Message: Could not compile handle bar "{{capitalizeAll ID.86}}" because "Parse error on line 1:
    {{capitalizeAll ID.86}}
    -------------------^
    Expecting 'ID', got 'NUMBER'" .Please correct and retry.

    What am I missing?

    0
  • David Gollom Strategic Partner
    Top Contributor
    Celigo University Level 4: Legendary
    Answer Pro
    Great Answer
    Engaged

    Hi AJ. Enclose your field name in square brackets.  Use [86] or [ID.86]

    0
  • AJ Nielsen

    That was very simple. I'm annoyed at myself for not having tried that. Thanks

    0
  • Steve Klett Strategic Partner
    Celigo University Level 4: Legendary
    Answer Pro
    Great Answer
    Top Contributor
    Awesome Follow-up
    Engaged

    Please add a pad() helper like freemarker has:

    https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_left_pad

    This is essential for fixed width templates (e.g., some EDI docs)

     

    0
  • Stephen Brandt Documentation Manager Community moderator
    Celigo University Level 4: Legendary
    Engaged
    Great Answer
    Top Contributor

    Thanks, Steve Klett. I've added your insight to Product Board partner and customer request. 

    0

Please sign in to leave a comment.