<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to query on local data?</title><link>https://community.appian.com/discussions/f/data/12954/how-to-query-on-local-data</link><description>I have an array of of CDT which have local data stored in it. Now I have to fetch data from the array based on some certain condition. For example, I have a CDT named &amp;quot;Employee&amp;quot; with fields firstName, lastName and employeeId. Now I want to get the firstName</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to query on local data?</title><link>https://community.appian.com/thread/58489?ContentTypeID=1</link><pubDate>Tue, 31 Jul 2018 06:07:44 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:37f60663-b8c8-4061-a74a-c7c10c42cf88</guid><dc:creator>Sudipta Biswas</dc:creator><description>Thank you all for helping me out. It&amp;#39;s working fine now.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to query on local data?</title><link>https://community.appian.com/thread/58322?ContentTypeID=1</link><pubDate>Wed, 25 Jul 2018 07:08:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9c78536a-6212-43a5-b7bc-e76d12b7c7b3</guid><dc:creator>Brazil Vibanco</dc:creator><description>&lt;p&gt;Hi &lt;a href="/members/sudiptab"&gt;Sudipta Biswas&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can also achive this using &lt;a href="https://docs.appian.com/suite/help/18.2/fnc_conversion_displayvalue.html"&gt;displayvalue()&lt;/a&gt; function. Is another alternative, I don&amp;#39;t know if better performance, but I like it.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;load(
  local!employee:{
    {id:23456,firstName:&amp;quot;xyz23456&amp;quot;,lastName:&amp;quot;def&amp;quot;};
    {id:12345,firstName:&amp;quot;abc12345&amp;quot;,lastName:&amp;quot;def&amp;quot;}
  },
  displayvalue(
    23456,
    local!employee.id,
    local!employee.firstName,
    null
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to query on local data?</title><link>https://community.appian.com/thread/58283?ContentTypeID=1</link><pubDate>Tue, 24 Jul 2018 08:51:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:63d3a84e-163b-4d61-81b4-c29a9e948653</guid><dc:creator>shwetad7106</dc:creator><description>Hi,&lt;br /&gt;
&lt;br /&gt;
You can make use of wherecontains() and index() functions,&lt;br /&gt;
&lt;br /&gt;
load(&lt;br /&gt;
local!employee:{&lt;br /&gt;
  {employeeId:12345,firstname:&amp;quot;abc&amp;quot;},&lt;br /&gt;
  {employeeId:1345,firstname:&amp;quot;ghj&amp;quot;},&lt;br /&gt;
  {employeeId:12345,firstname:&amp;quot;xyz&amp;quot;}&lt;br /&gt;
},&lt;br /&gt;
local!indexes : wherecontains(12345,tointeger(local!employee.employeeId)), /*this will return the index of the row which has this employeeId.*/&lt;br /&gt;
local!data:index(local!employee,local!indexes,{}),   /* this will return data at that indexes */&lt;br /&gt;
local!data&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
Try above code.&lt;br /&gt;
&lt;br /&gt;
Thank you.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to query on local data?</title><link>https://community.appian.com/thread/58282?ContentTypeID=1</link><pubDate>Tue, 24 Jul 2018 08:51:53 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:72261c15-f15a-401f-8337-4d6de81bbb05</guid><dc:creator>Shubham Aware</dc:creator><description>Hello,&lt;br /&gt;
&lt;br /&gt;
There are multiple ways by which you can retrieve data from local! variable like&lt;br /&gt;
1) filter() function &lt;br /&gt;
2) Use array function like whereContains, index&lt;br /&gt;
&lt;br /&gt;
 whereContains(&amp;quot;12345&amp;quot;,index(ri!Employee, &amp;quot;firstName&amp;quot;))&lt;br /&gt;
By this you will gate index of particular data in cdt.&lt;br /&gt;
&lt;br /&gt;
Thanks,&lt;br /&gt;
Shubham&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to query on local data?</title><link>https://community.appian.com/thread/58280?ContentTypeID=1</link><pubDate>Tue, 24 Jul 2018 07:25:50 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9fa1ebf5-0c68-48e5-9a5b-5883271dbcc5</guid><dc:creator>nitesht9652</dc:creator><description>Hi,&lt;br /&gt;
&lt;br /&gt;
Please run the below code in expression rule:&lt;br /&gt;
&lt;br /&gt;
load(&lt;br /&gt;
  local!employee:{{id:23456,firstName:&amp;quot;xyz23456&amp;quot;,lastName:&amp;quot;def&amp;quot;};{id:12345,firstName:&amp;quot;abc12345&amp;quot;,lastName:&amp;quot;def&amp;quot;}},&lt;br /&gt;
  local!result:a!forEach(items:local!employee,&lt;br /&gt;
  expression: if((tointeger(fv!item.id)=12345),fv!item.firstName,{})),&lt;br /&gt;
  local!result&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
It should return &amp;quot;abc12345&amp;quot; which is first name for the employee having id as 12345.&lt;br /&gt;
&lt;br /&gt;
Thanks,&lt;br /&gt;
Nitesh&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to query on local data?</title><link>https://community.appian.com/thread/58247?ContentTypeID=1</link><pubDate>Mon, 23 Jul 2018 15:18:19 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5e318036-0e8a-4ed2-9f6d-0ee6a017782a</guid><dc:creator>Robert Shankin</dc:creator><description>&lt;p&gt;Hi -&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.appian.com/suite/help/18.2/fnc_array_wherecontains.html#examples" target="_blank"&gt;Perhaps this pattern will help&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;code class="highlighter-rouge"&gt;index(pv!employees.firstName, wherecontains(&amp;quot;Finance&amp;quot;, pv!employees.department))&lt;/code&gt;&amp;nbsp;returns the first names of all employees with their department field set to&amp;nbsp;&lt;code class="highlighter-rouge"&gt;Finance&lt;/code&gt;&amp;nbsp;or an empty array if none have it set to&amp;nbsp;&lt;code class="highlighter-rouge"&gt;Finance&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:inherit;"&gt;In your case, you want change:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:inherit;"&gt;PV -&amp;gt; local,&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:inherit;"&gt;&amp;quot;Finance&amp;quot; -&amp;gt; &amp;quot;12345&amp;quot;,&lt;br /&gt;&lt;/span&gt;.department -&amp;gt; .employeeId&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to query on local data?</title><link>https://community.appian.com/thread/58242?ContentTypeID=1</link><pubDate>Mon, 23 Jul 2018 11:37:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:96445bb6-66b8-4529-9222-c70a5afa480c</guid><dc:creator>harrisont606</dc:creator><description>Appian looping functions like filter can help you take care of this.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to query on local data?</title><link>https://community.appian.com/thread/58241?ContentTypeID=1</link><pubDate>Mon, 23 Jul 2018 11:36:33 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1b9ceffe-40d2-4e81-bc20-1036c170ea82</guid><dc:creator>chetany</dc:creator><description>&lt;p&gt;You can use the filter() function.&lt;br /&gt; First you need to create a rule which takes A .one Employee CDT as input B. the id/name to filter on.&lt;br /&gt; This rule should return true if the EmployeeCDT.name is equal to given givenName or EmployeeCDT.id equal to id.&lt;br /&gt; Example:&lt;/p&gt;
&lt;p&gt;local!filteredEmployee: filter( rule!returnTrueIfEmployeeHasId( _, 12345) , ri!arrayOfEmployeeCDT ).&lt;/p&gt;
&lt;p&gt;Then just access the name using local!filteredEmployee.name&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; Here the rule returnTrueIfEmployeeHasId is assumed to be created already.&lt;br /&gt; It has some condition like this:&lt;br /&gt; ri!cdtEmployee.id = ri!inputId&lt;br /&gt; &lt;br /&gt; Note: you could extend this pattern and create child rules for each of the filters possible. (say filter by name, filter by id etc.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>