<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Nifi : Is it possible to create multiple flow file based on attributes ? in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Is-it-possible-to-create-multiple-flow-file-based-on/m-p/341405#M233518</link>
    <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I receive a json from a HTTP Request. It looks like this :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "accessToken" : "token",
  "expiresIn" : "12600",
  "refreshToken" : "token",
  "tokenType" : "Bearer",
  "usagePointsId" : "22516914714270, 22516914714270, 22516914714270"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the usagePointsId key containing a string with multiple values.&amp;nbsp;&lt;BR /&gt;I will need each values to include them in different API calls.&lt;BR /&gt;I would therefore like to be able to separate the string at the comma level to extract each value.&lt;BR /&gt;Then the idea is to create a new unique flow file for each value. This value would be associated with a "usagePointId" attribute which would be used in my API calls.&amp;nbsp;Also, the others json key would be added as Attributes for each flow files&lt;BR /&gt;&lt;BR /&gt;I don't know if it's possible to create multiple differents flow file based on a split attributes.&amp;nbsp;&lt;BR /&gt;I tried to use the ExecuteScript (with ECMASCRIPT) to split the string and create Flow Files with something like this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;flowFile = session.get()

if (!flowFile) return
usagePointsId = flowFile.getAttribute('usagePointsId')
splitStr = usagePointsId.split(",");
let attrs = []

for (let i = 0; i &amp;lt; spltStr.length, i+) {
	newFlowFile = session.create()
	newFlowFile = session.write(newFlowFile, splitStr[i] )
	session.transfer(newFlowFile, REL_SUCCESS)
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Someone could help me with that kind of issue ?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 14 Apr 2022 10:36:30 GMT</pubDate>
    <dc:creator>azg</dc:creator>
    <dc:date>2022-04-14T10:36:30Z</dc:date>
    <item>
      <title>Nifi : Is it possible to create multiple flow file based on attributes ?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Is-it-possible-to-create-multiple-flow-file-based-on/m-p/341405#M233518</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I receive a json from a HTTP Request. It looks like this :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "accessToken" : "token",
  "expiresIn" : "12600",
  "refreshToken" : "token",
  "tokenType" : "Bearer",
  "usagePointsId" : "22516914714270, 22516914714270, 22516914714270"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the usagePointsId key containing a string with multiple values.&amp;nbsp;&lt;BR /&gt;I will need each values to include them in different API calls.&lt;BR /&gt;I would therefore like to be able to separate the string at the comma level to extract each value.&lt;BR /&gt;Then the idea is to create a new unique flow file for each value. This value would be associated with a "usagePointId" attribute which would be used in my API calls.&amp;nbsp;Also, the others json key would be added as Attributes for each flow files&lt;BR /&gt;&lt;BR /&gt;I don't know if it's possible to create multiple differents flow file based on a split attributes.&amp;nbsp;&lt;BR /&gt;I tried to use the ExecuteScript (with ECMASCRIPT) to split the string and create Flow Files with something like this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;flowFile = session.get()

if (!flowFile) return
usagePointsId = flowFile.getAttribute('usagePointsId')
splitStr = usagePointsId.split(",");
let attrs = []

for (let i = 0; i &amp;lt; spltStr.length, i+) {
	newFlowFile = session.create()
	newFlowFile = session.write(newFlowFile, splitStr[i] )
	session.transfer(newFlowFile, REL_SUCCESS)
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Someone could help me with that kind of issue ?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 10:36:30 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Is-it-possible-to-create-multiple-flow-file-based-on/m-p/341405#M233518</guid>
      <dc:creator>azg</dc:creator>
      <dc:date>2022-04-14T10:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi : Is it possible to create multiple flow file based on attributes ?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Is-it-possible-to-create-multiple-flow-file-based-on/m-p/341440#M233522</link>
      <description>&lt;P&gt;I tried to transform the usagePointsId String to an array of element using a jolt transformation :&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    {
    "operation": "modify-overwrite-beta",
    "spec": {
        "usagePointsId": "=split(',',@(1,usagePointsId))"
    }
  }&lt;/LI-CODE&gt;&lt;P&gt;output :&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;"usagePointsId" : [ "22516914714270", " 22516914714271", " 22516914714272" ]&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Then i split this array with SplitJson on the usagePointsId path.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="azg_0-1649948491867.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/34172i787BDF000B9F3631/image-size/medium?v=v2&amp;amp;px=400" role="button" title="azg_0-1649948491867.png" alt="azg_0-1649948491867.png" /&gt;&lt;/span&gt;&lt;BR /&gt;It results multiple files with a simple string in content :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="azg_1-1649948555431.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/34173i2A51FBFD0DF5D484/image-size/medium?v=v2&amp;amp;px=400" role="button" title="azg_1-1649948555431.png" alt="azg_1-1649948555431.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How can i save that kind of data as Attributes ? I try to use EvaluateJsonPath but unfortunatly, there is no path to precise. Is there a way to handle that ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 15:05:34 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Is-it-possible-to-create-multiple-flow-file-based-on/m-p/341440#M233522</guid>
      <dc:creator>azg</dc:creator>
      <dc:date>2022-04-14T15:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi : Is it possible to create multiple flow file based on attributes ?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Nifi-Is-it-possible-to-create-multiple-flow-file-based-on/m-p/341455#M233527</link>
      <description>&lt;P&gt;I finally used a Jolt transformation on the last ouput content :&lt;BR /&gt;input :&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;22516914714270&lt;/LI-CODE&gt;&lt;P&gt;jolt spec :&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
     "operation": "shift",
    	"spec": {
          "*": {
                  "$": "usagePointsId"
          }
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;ouput :&lt;BR /&gt;{"usagePointsId": "22516914714270"}&lt;BR /&gt;&lt;BR /&gt;Then i used the EvaluateJsonPath to save the value as attributes&lt;/P&gt;&lt;P&gt;What a day&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 16:06:43 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Nifi-Is-it-possible-to-create-multiple-flow-file-based-on/m-p/341455#M233527</guid>
      <dc:creator>azg</dc:creator>
      <dc:date>2022-04-14T16:06:43Z</dc:date>
    </item>
  </channel>
</rss>

