Forum Discussion
I wanted to provide a solution that used the expression language in case others are interested.
Strings have a split()
method that will split the string and return an array. From there, you can use the map()
method to create key/value pairs, like so:
$Roles.split(',').map((elem, index) => ["Role" + (index + 1), elem])
(The argument to map()
is a callback function that will be called with each element in the array and its index. The function then creates an array with the first element being the property name “RoleN” and the second being the element itself.)
Once you have key/value pairs, you can feed it into the extend()
method on objects to produce an object with the given pairs:
$.extend($Roles.split(',').map((elem, index) => ["Role" + (index + 1), elem]))
Here’s an example pipeline:
SplitRoles_2019_01_24.slp (6.7 KB)
Hello tstack,
I am trying to something similar, however, it is not working for me. I have a Json field that is comma-delimited named “instructors”. Sometimes this field contains one instructor id number, and sometimes it contains two. I would like these to go into separate table columns of Instructor1 and Instructor2.
I my instructor mapper I did:
and my second mapper I did:
My pipeline validates, however, there is no output from my second mapper.
I would greatly appreciate any assistance you can provide.
Thanks,
sawierman
The error documents created by most snaps include a ‘snap_details’ property that contains the label of the snap. So, you can build the error pipeline to work with that property. As for writing to separate files, the JSON Formatter snap now has the ability to insert document data into the header of the binary output document. The File Writer can then be configured to create the output file name based on values in the header. I’m attaching an example project to demonstrate this flow, it contains a Main pipeline with some errors that are sent to the ErrorHandler pipeline. Note that creating separate files for every error document will be fairly slow, so it might work better to create a single file.
ErrorPipelineDemo.zip (2.9 KB)