cancel
Showing results for 
Search instead for 
Did you mean: 

Most Efficient Way to Copy Values From Parent Object to Multi-Instance Child Object

wcl3y2
New Contributor III

Hi,

I’m looking for the most efficient way to copy values from a parent object to a multi-instance child object. For instance, if I need start and end dates from an order header on the order lines.

I should also add that I’d like to rename some of the attributes. I’ve been able to do this with the structure snap, but instead of creating a string, it creates an array.

Thanks,
Will

4 REPLIES 4

ptaylor
Employee
Employee

Hi,

To copy a field from the root object into the child objects, try a combination of the map and extend functions of the expression language:

image

Here’s another variant that just uses map and an object literal which both copies the date and renames the index to lineNum:

image

wcl3y2
New Contributor III

Yes, this works. I just wanted to see if there was a standard snap that would be more straight-forward and to make sure there aren’t any performance concerns with using map and extend.

Depending on your use case, it might be possible to use the JSON Splitter instead. It can split the child array into separate output documents, and copy any desired fields from the parent (using Include Paths) or all of the parent’s fields (using Include scalar parents). But I wouldn’t worry about a potential performance with Mapper unless you observe an actual performance issue with Mapper.

Hope that helps.

wcl3y2
New Contributor III

Sounds good, thanks for your help!