Answered

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?

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?

Scenario is:

1) If Lines[*].Net_Amount > 0 (in case of positive value), then Lines[*].Debit = Lines[*].Net_Amount else Lines[*].Debit = "0" (in case of negative value, it should be 0)

2) If Lines[*].Net_Amount < 0 (in case of negative value), then Lines[*].Credit = Lines[*].Net_Amount else Lines[*].Credit = "0" (in case of positive value, it should be 0)

How do I write a handlebars expression for the same?

 

0

Comments

7 comments
Date Votes
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post