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
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
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
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:
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?
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".
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?
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:
Let us know if this works for you.
Please sign in to leave a comment.