In Import Mapping while creating Journal Entries, for one one of the fields I need to use the case or If-else statement. How do I use the if-else statement using handlebars?

Answered

Comments

7 comments

  • Swapnil Shah
    Celigo University Level 4: Legendary
    Engaged
    Awesome Follow-up

    Hi Godishela Sachin Goud ,

    The Hook is working for me and I am successfully able to post the records and create Journal Entries. Thank you so much for investing your valuable time and providing me with the solution. 

    Also thanks to everyone in the community who helped me with this issue.

    Regards,

    Swapnil Shah

    1
  • Anitha Abraham Community moderator Principal Technical Writer
    Celigo University Level 3: Master

    Hi Swapnil,

    Thanks for posting this to the community! I’m checking with our experts. In the meantime, you might find this article helpful.

    Anitha 

     

    0
  • Swapnil Shah
    Celigo University Level 4: Legendary
    Engaged
    Awesome Follow-up

    Hi Anitha,

    Thank you for the article. I actually use that article frequently for handlebars uses and I did try if if/else and compare helpers but somehow it didn't work for me. Maybe I am not using the correct syntax or Celigo doesn't support nesting of handlebars.

    This is what I tried in mapping but its not working:

     

    0
  • Swapnil Shah
    Celigo University Level 4: Legendary
    Engaged
    Awesome Follow-up

    Hi Stephen,

    Without the curly braces, its giving me NULL value for Line:Debit

    The handlebars expression I am using for Line:Debit seems to be working for me but the one for Line:Credit is not working. Is it because I am using #compare and #multiply handlebars together within the same expression?

    0
  • Sachin Goud Godishela Software Engineer
    Answer Pro
    Great Answer
    Celigo University Level 4: Legendary

    Hi Swapnil,

    For Line: Credit, as you suspected, it's failing because you're using multiply and compare together. I suggest you try this expression - "set 0 if value is positive, set abs(value) if value is negative".

    {{divide (subtract (abs value) value) 2}}
    0
  • Swapnil Shah
    Celigo University Level 4: Legendary
    Engaged
    Awesome Follow-up

    Hi 

    It seems like the handlebar which you suggested will solve my issue. So I replaced the value with Lines[*].Net_Amount and then tried this handlebar: {{divide (subtract (abs Lines[*].Net_Amount) Lines[*].Net_Amount) 2}} but it is giving me Null Values for Line: Credit.

    Is there any syntax issue in this?

    0
  • Sachin Goud Godishela Software Engineer
    Answer Pro
    Great Answer
    Celigo University Level 4: Legendary

    Hi Swapnil,

    The handlebar expression seems to be working only for body level fields and not for line level fields. I suggest you to configure a simple preMap hook script which generates 2 fields (debit_amount and credit_amount) with desired values which can be mapped directly without the need of handlebars.

    Please refer to the attached screenshots. To learn more about hooks, please go through this article.

     

    Script Code:


    function preMap (options) {
      return options.data.map((d) => {
        let o = {
          data: d
        }
      o.data.Lines.forEach((line) => {
         line.debit_amount = line.Net_Amount > 0 ? line.Net_Amount : 0
         line.credit_amount = line.Net_Amount > 0 ? 0 : -line.Net_Amount
        })
        return o
      })
    }

    Let us know if this works for you.

    0

Please sign in to leave a comment.