<?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>topic Re: Can we filter a complex structure? in Workato Pros Discussion Board</title>
    <link>https://systematic.workato.com/t5/workato-pros-discussion-board/can-we-filter-a-complex-structure/m-p/5783#M2533</link>
    <description>&lt;P&gt;Workato doesn't support the filter method for arrays, which&amp;nbsp;&lt;EM&gt;would&lt;/EM&gt; allow you block process all of the array's items. The easiest alternative to do this (IMO) is to put the payload into a Ruby action and write some code to get what you need. Ruby syntax is quite straightforward, and using the Ruby action is a piece of cake.&lt;/P&gt;&lt;P&gt;The gist of the action is quite simple. First, name the action and then create your input schema to pass in your code:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gary1_1-1701840367682.png" style="width: 400px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/909i92471EB2DD375E93/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="gary1_1-1701840367682.png" alt="gary1_1-1701840367682.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Then, I prefer to write the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;## reference your input like this
a = input["data"]

## do some stuff
b = a + a

## declare an object to return as output
{result: b}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally (now that you finished your code), create an output schema to match your output object. This will create data pills that could be used in the following steps.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gary1_2-1701840438637.png" style="width: 400px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/910i0709CBC8767D7B70/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="gary1_2-1701840438637.png" alt="gary1_2-1701840438637.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Run it, and you'll get this as output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gary1_4-1701841631588.png" style="width: 400px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/912i924BDBBC308B52E7/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="gary1_4-1701841631588.png" alt="gary1_4-1701841631588.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Once you have the basics down, this because extremely powerful. Need to do something that requires more complexity than in-line formulas support? Need to loop through a million items (literally) but don't want to spend a million tasks? Do it in one task by using a Ruby action! It's game changing. (You can also do with with JavaScript or Python if that's your cup of tea.)&lt;/P&gt;&lt;P&gt;In the interest of saving you time, here's what you need. Drop this code in a Ruby action and it should do the trick:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;## provide the findIdentifiers array as your "data" input and grab it
array = input["data"]

## create an empty array to store your keepers
itemsToKeep = []

## loop through findIdentifiers
array.each { | a | 
  
  ## dig up the type value; this assumes only one object in the Type array 
  type = a["value"]["Type"][0]["value"]
  
  ## test the type value with a ternary operation, 
  ## which is just simplified shorthand for an if statement.
  ## if the type is right, push it to itemsToKeep
  type == "Type1" ? itemsToKeep.push(a) : null
  
}

## create the output object with itemsToKeep as the value
{result: itemsToKeep}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you remove all of the comments, this is a whopping six lines of code.&lt;/P&gt;&lt;P&gt;To test it, I provided this JSON as input with the goal of only retaining the first and third item in the array (Type1):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
	"findIdentifier": [{
			"label": "ONE - KEEP",
			"value": {
				"Type": [{
					"type": "blah blah type",
					"ov": true,
					"value": "Type1",
					"uri": "blah blah uri"
				}],
				"ID": [],
				"Status": [],
				"ov": true,
				"uri": "blah uri"
			}
		},
		{
			"label": "TWO - DON'T KEEP",
			"value": {
				"Type": [{
					"type": "blah blah type",
					"ov": true,
					"value": "Type2",
					"uri": "blah blah uri"
				}],
				"ID": [],
				"Status": [],
				"ov": true,
				"uri": "blah uri"
			}
		},
		{
			"label": "THREE - KEEP",
			"value": {
				"Type": [{
					"type": "blah blah type",
					"ov": true,
					"value": "Type1",
					"uri": "blah blah uri"
				}],
				"ID": [],
				"Status": [],
				"ov": true,
				"uri": "blah uri"
			}
		}
	]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here is the result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gary1_3-1701841479955.png" style="width: 400px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/911i8126A078D1D03108/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="gary1_3-1701841479955.png" alt="gary1_3-1701841479955.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
    <pubDate>Wed, 06 Dec 2023 05:51:53 GMT</pubDate>
    <dc:creator>gary1</dc:creator>
    <dc:date>2023-12-06T05:51:53Z</dc:date>
    <item>
      <title>Can we filter a complex structure?</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/can-we-filter-a-complex-structure/m-p/5777#M2532</link>
      <description>&lt;P&gt;I have an array of complex data (see screen shot) - I want to find the top level array where an inner level value is matched&lt;/P&gt;&lt;P&gt;In the example below there are 3 main array elements - and in a nested level for Type&amp;nbsp; there is a value of 'Type1' for 2 of the 3 items in the outer array.&lt;/P&gt;&lt;P&gt;Is there a way to return only the array elements that are of&amp;nbsp; value 'Type1' in the example below?&amp;nbsp; Only thing I've found that I can do is create a List (Workato variables) and map the 'value' fields for Type, ID, Status fields...and then filter the list for what I want.&amp;nbsp; Was hoping to find a way to do this all inside a formula in order to facilitate bulk operations.&amp;nbsp; I've played around with .where condition in multiple ways but simply haven't been able to figure out what syntax I can use to filter the list so that the whole outer array item is returned.&amp;nbsp; I can pluck my way down to the inner list...but then I lose the other fields and only have the plucked field...which is not useful..&amp;nbsp; want to filter on 'Type' and use that to get the value for 'ID'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="michellepopovi_0-1701827996209.png" style="width: 400px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/906i0A225E60988E2C42/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="michellepopovi_0-1701827996209.png" alt="michellepopovi_0-1701827996209.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="michellepopovi_1-1701828341898.png" style="width: 400px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/907i6621709D8711F9EC/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="michellepopovi_1-1701828341898.png" alt="michellepopovi_1-1701828341898.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 02:09:47 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/can-we-filter-a-complex-structure/m-p/5777#M2532</guid>
      <dc:creator>michelle-popovi</dc:creator>
      <dc:date>2023-12-06T02:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can we filter a complex structure?</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/can-we-filter-a-complex-structure/m-p/5783#M2533</link>
      <description>&lt;P&gt;Workato doesn't support the filter method for arrays, which&amp;nbsp;&lt;EM&gt;would&lt;/EM&gt; allow you block process all of the array's items. The easiest alternative to do this (IMO) is to put the payload into a Ruby action and write some code to get what you need. Ruby syntax is quite straightforward, and using the Ruby action is a piece of cake.&lt;/P&gt;&lt;P&gt;The gist of the action is quite simple. First, name the action and then create your input schema to pass in your code:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gary1_1-1701840367682.png" style="width: 400px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/909i92471EB2DD375E93/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="gary1_1-1701840367682.png" alt="gary1_1-1701840367682.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Then, I prefer to write the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;## reference your input like this
a = input["data"]

## do some stuff
b = a + a

## declare an object to return as output
{result: b}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally (now that you finished your code), create an output schema to match your output object. This will create data pills that could be used in the following steps.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gary1_2-1701840438637.png" style="width: 400px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/910i0709CBC8767D7B70/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="gary1_2-1701840438637.png" alt="gary1_2-1701840438637.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Run it, and you'll get this as output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gary1_4-1701841631588.png" style="width: 400px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/912i924BDBBC308B52E7/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="gary1_4-1701841631588.png" alt="gary1_4-1701841631588.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Once you have the basics down, this because extremely powerful. Need to do something that requires more complexity than in-line formulas support? Need to loop through a million items (literally) but don't want to spend a million tasks? Do it in one task by using a Ruby action! It's game changing. (You can also do with with JavaScript or Python if that's your cup of tea.)&lt;/P&gt;&lt;P&gt;In the interest of saving you time, here's what you need. Drop this code in a Ruby action and it should do the trick:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;## provide the findIdentifiers array as your "data" input and grab it
array = input["data"]

## create an empty array to store your keepers
itemsToKeep = []

## loop through findIdentifiers
array.each { | a | 
  
  ## dig up the type value; this assumes only one object in the Type array 
  type = a["value"]["Type"][0]["value"]
  
  ## test the type value with a ternary operation, 
  ## which is just simplified shorthand for an if statement.
  ## if the type is right, push it to itemsToKeep
  type == "Type1" ? itemsToKeep.push(a) : null
  
}

## create the output object with itemsToKeep as the value
{result: itemsToKeep}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you remove all of the comments, this is a whopping six lines of code.&lt;/P&gt;&lt;P&gt;To test it, I provided this JSON as input with the goal of only retaining the first and third item in the array (Type1):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
	"findIdentifier": [{
			"label": "ONE - KEEP",
			"value": {
				"Type": [{
					"type": "blah blah type",
					"ov": true,
					"value": "Type1",
					"uri": "blah blah uri"
				}],
				"ID": [],
				"Status": [],
				"ov": true,
				"uri": "blah uri"
			}
		},
		{
			"label": "TWO - DON'T KEEP",
			"value": {
				"Type": [{
					"type": "blah blah type",
					"ov": true,
					"value": "Type2",
					"uri": "blah blah uri"
				}],
				"ID": [],
				"Status": [],
				"ov": true,
				"uri": "blah uri"
			}
		},
		{
			"label": "THREE - KEEP",
			"value": {
				"Type": [{
					"type": "blah blah type",
					"ov": true,
					"value": "Type1",
					"uri": "blah blah uri"
				}],
				"ID": [],
				"Status": [],
				"ov": true,
				"uri": "blah uri"
			}
		}
	]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here is the result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gary1_3-1701841479955.png" style="width: 400px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/911i8126A078D1D03108/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="gary1_3-1701841479955.png" alt="gary1_3-1701841479955.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 05:51:53 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/can-we-filter-a-complex-structure/m-p/5783#M2533</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2023-12-06T05:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Can we filter a complex structure?</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/can-we-filter-a-complex-structure/m-p/7716#M3265</link>
      <description>&lt;P&gt;&lt;a href="https://systematic.workato.com/t5/user/viewprofilepage/user-id/1188"&gt;@gary1&lt;/a&gt;&amp;nbsp;How would you pass in the Json arrays when the input variable for ruby or java action doesn't supports array or list type?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2567-09-16 at 21.52.30.png" style="width: 400px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/1555i1BCD1864F1D50030/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Screenshot 2567-09-16 at 21.52.30.png" alt="Screenshot 2567-09-16 at 21.52.30.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 14:54:42 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/can-we-filter-a-complex-structure/m-p/7716#M3265</guid>
      <dc:creator>Chaiphat</dc:creator>
      <dc:date>2024-09-16T14:54:42Z</dc:date>
    </item>
  </channel>
</rss>

