Handlebars mapping commas

Comments

3 comments

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

    Hi, Hristina Bendeva. I got the same error with your code. The following change seemed to work in Dev playground, from:

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

    to:

    {{#if @last}}{{else}},{{/if}}

    Sorry – I can't figure out why the second block worked, but not the first. Let us know if that doesn't solve the problem for you, too.

     

    0
  • Hristina Bendeva NetSuite Integration Whiz
    Awesome Follow-up
    Engaged
    Celigo University Level 4: Legendary

    Hello Stephen Brandt,

    I have a problem with placing commas after the elements in the items_info list not the shipments list, the JSON I uploaded for the payload had errors in it and it didn't display the problem I have, I updated the JSON and it displays the problem now, also here are some screenshots as well: 

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

    Thanks, Hristina Bendeva. Now I'm seeing the same error. Sorry for the hasty reply yesterday. 

    The reason you can't rely on @last in this case is because of the #compare logic. 

    I ran a few tests, and the @index and @last values were all correctly maintained within the context of every #each loop.

    So, at the inner nesting for "items_info", you will have four iterations: 0, 1, 2, and 3. The @last value will be [true when the index is] 3, given your sample data. However, in only one case in your sample data does the last item match an array item's index in your #compare statement, omitting the comma. 

    That's an explanation, but not a solution. You'd have to check @last outside of the current #compare blocks, which could get tricky with other @../last and @../../last indices also in play.

    There might be something easier and quicker, according to your business rules, like leaving blank "items_info" objects, if that's allowed. 

     

     

     

    0

Please sign in to leave a comment.