Mapper 2.0 - how to conditionally add Object to output?
Oh boy.... I just hit what could be a showstopper (imagine sadface emoji)
OK, new integration with HARD deadline fast approaching. There is an Object property in the request JSON called 'device' that should only be included if there is data in certain input properties.
Here's a screen shot to illustrate:
The 'device' property should only be included if session_id and browser_ip have data. I clicked the options for the device mapping and there aren't any options to control it's inclusion.
The only idea I have is to change the shape of my input data so it's already in the desired request format, then do a single mapping of the whole thing, which should be ignored if the input data is missing.
Any other ideas?
Comments
Hello Steve,
You could achieve that using handlebars expression in Mapper 2.0. This article should help.
Note: Handlebars expression syntax is the same as AFE editors in the product and does not use JSONPAth notation ($.....)
Hi Steve, You can do a conditional branch on your source data to look for data in those two fields, send the valid records to be mapped and send the records w/ empty fields to a ftp or somewhere to record as incomplete. More info on conditional branching : https://docs.celigo.com/hc/en-us/articles/7287177264795-Apply-branching-to-your-flow
Steve Klett, Amanjot Singh and I discussed and you are correct in that there is no way to currently do this with mapper 2.0. We do have this on the backlog due to it being required for other functionality, like EDI, so we'll add the feedback to that.
Joe Hottinger's suggestion would work, but then you would end up with 2 different import steps.
Also, to add another cook to this kitchen, a simple preMap script could handle it where you just remove the device field if those fields don't exist, then use mapper 2.0 copy function like this:
Thanks Amanjot Singh, though I looked at the docs and was trying to figure out what you had in mind with Handlebars. Now I see from Tyler it won't actually work, but I appreciate the reply.
Joe Hottinger also a good suggestion as a last resort, I'm sure we all try to avoid duplicating complex stuff like mapping, but it would have worked if nothing else would. Thanks for the help!
Tyler Lamparter We mind-melded. I banged out a quick and simple pre map script to pre-generate my API object then conditionally mapped it "as-is". For anyone else that finds this thread, I did something like this:
Then in Mapper2:
Rich tools to conditionally control mapping would be great, I look forward to it. :)
I am attempting to do the same thing… use handlebar helpers on a JSON path.
{{compare $.line_items.Shipped_Quantity '>' 0}}{{$.line_items.item_id}}{{/compare}}
Message: Parse error on line 1:
...line_items.item_id}}{{/compare}}
-----------------------^
Expecting 'EOF', got 'OPEN_ENDBLOCK'. The use of JSON Path in the Handlebars expression might have caused this problem.
Is this still not possible? Celigo AI seems to think so ;-)
Chris Huovinen Celigo AI must be hallucinating this is still not possible and JSON Path does not work in handlebar expressions.
Please sign in to leave a comment.