Forum Discussion

Max's avatar
Max
New Contributor II
2 years ago
Solved

Divide a comma separated list of strings

Hello, I have a requirement to convert the following MuleSoft dataweave code into snap logic... rpns default '' splitBy ',' distinctBy $ divideBy 245 map ((item, index) -> 'searchCriteria': (item j...
  • koryknick's avatar
    2 years ago

    Max - please download the attached ZIP file, decompress it, and import the SLP as a POC pipeline.  

    There are many other ways to solve this and others in the Community may provide you with alternate solutions, but I wanted to try to keep this example fairly simple.

    "Split values" uses a JSON Splitter snap and jsonPath function to get the searchCriteria.values array as individual documents.  This is done in the event you have more than one set of searchCriteria array elements.  

    "Split comma separated string" uses a Mapper snap with the String.split() method to change the comma-separated list into an array for each element.  

    "Split on array" uses another JSON Splitter to turn each array element into a JSON document.

    "Group by 2" is a Group by N snap that simply combines the incoming documents into arrays of size N: 2 in this case.

    Finally, "Create comma separated list" is another Mapper that uses jsonPath and the Array.join() method to recreate a single string per input document, which is a comma-separated list for your search criteria in the requested format.

    Hope this helps!