I am continuing my journey of trying to learn to use Make mostly through reverse engineering and trial and error…and have gotten much more proficient…but have run into a tricky problem (well…tricky for me anyways)
What I want to do:
retrieve an xml file that contains an order header and line items
pass back that same xml with updated acknowledgement fields
when the order ships, send back an xml with invoice information. the invoice xml format is nearly identical to the order xml I received, but with several different fields (some eliminated, some added)
I’m grabbing the xml and dropping it into a datastore with a data structure defined by the xml
then i have a separate data store that is tracking status changes for each order…
all of which works fine.
But i can’t figure out the right way to transform the xml in the original order datastore to the format needed for the invoice xml
a simplified representation of what I’m trying to do…
I receive something that looks like:
< ordernum>1234< /ordernum>
< date>2023-01-01< /date>
some of the actual data they pass through to me only resides in their system and I just need to pass it back… so I’m storing everything in a datastore
where I’m getting a bit stuck is the best way to iterate through the line items in the xml structure (from the datastore) and then create the new invoice xml which includes both elements from the original order as well as updated data from my system.
convert the xml to an array and then manipulate it (get/map)? use the iterator/aggregator?
I’ve tried both approaches and keep getting tied in knots…I’m not really clear on how to iterate through the xml from the data store and put it back together again in the correct format
more specifically…I can get most of what I need done by calling the data store with the original order, iterating through the lines, creating xml and then aggregating into an array and then mapping the lines in the ‘create invoice xml’ module to the output of the aggregator…like this:
But I’m getting odd formatting I can’t seem to resolve. “<” and “>” are replaced with "<" and ">"…there’s an extra opening and closing of the < lines> tag between each line item (the structure is < lines> then < invoice line> ) and there’s an extra < xml> as well
so…I have progressed things, but still not sure I’m any closer.
logic: grab original order xml from data store, iterate through the lines, create line items xml, aggregate that into a table, aggregate that into an array, insert the array into a matching invoice xml to a mapped “lines” field
all of the inputs and outputs of each module look like they’re correct, but I just keep getting an “Invalid collection in parameter ‘INVOICE_LINE’.” error. when I try to insert into either the array aggregator or directly into the create xml module
OK…got it to work, even though its not pretty. leaving my ‘solution’ in case its helpful for anyone…but I think the real issue is I just don’t understand how to work with arrays effectively. I just couldn’t figure out the right way to get the xml created for each line out of the array and into the ‘full’ xml for the invoice.
What I’ve ended up doing is: get the xml from the datastore; iterate through the lines and add in the updated data required for each and turn that into xml. build a variable that concatenates the output on each iteration. Then build the Invoice xml and insert the raw text from the concatenated variable that contains the line items into the right spot of the invoice xml
Appreciate the feedback! I think where I’m consistently getting stuck though is in creating “nested” JSON or XML files. eg a varying number of line items inside a bigger “order”
I’ve tried both JSON and XML…and conceptually it makes sense to me (iterate through line items and create xml/json for those…then create a json or xml ‘order’ and then map the line items from the prior module to the line items in the order json/xml
…except I cant seem to make it work. it either tries to insert as a txt string, or i get a general error when it tries to run, or i can’t get things to work out in general.
is there a good tutorial for nested json/xml for Make in general? it feels like the answer is right in front of me but i just can’t see it…
There isn’t really a tutorial for something like this, because it’s very case specific. Each use case has a dfiferent input/output which makes it hard to create something generic.
The one thing I could usually say; use an iterator for every array you want to iterate over. Then aggregate it all together at the end, and make sure you set JSON structure.