<?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>Query data</title><link>https://community.appian.com/discussions/f/new-to-appian/35003/query-data</link><description>Hi Everyone, 
 I am querying the db table through query record type. This query gives the list of db records. When I am using this in interface and using index to get the particular field, it gives this list of particular field. In case of null or single</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Query data</title><link>https://community.appian.com/thread/135559?ContentTypeID=1</link><pubDate>Sat, 18 May 2024 14:30:25 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f2ea3785-3eaf-4618-82d7-f6035ea61a1f</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;without seeing what exactly you&amp;#39;re trying and what exactly your query output / error is, it&amp;#39;s hard to say, but i&amp;#39;m guessing you&amp;#39;re mixing up indexing (in terms of array position) with trying to fetch the record type property (which needs to be fetched not with a dot property but either with square brackets that contain the record property reference, or in the &amp;quot;property()&amp;quot; function where the record type property reference is passed instead of the plaintext field name).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query data</title><link>https://community.appian.com/thread/135558?ContentTypeID=1</link><pubDate>Sat, 18 May 2024 11:51:32 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f1fd3855-7084-47a4-a537-a2f2b20e6c80</guid><dc:creator>Rahul009</dc:creator><description>&lt;p&gt;Hi &lt;a class="internal-link view-user-profile" href="/members/mikes0011"&gt;Mike Schmitt&lt;/a&gt;, As per above, I am not sure if .data in recordtype will be supported. .data gives error &amp;quot;can only be indexed using square brackets&amp;quot; when there is one record in output. And if indexed using square brackets then it gives error &amp;quot;invalid index&amp;quot; when output is null.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query data</title><link>https://community.appian.com/thread/135501?ContentTypeID=1</link><pubDate>Fri, 17 May 2024 13:03:20 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:0d2b36b2-0879-4d1e-a576-7e63e952c094</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;I agree with what others have said about&amp;nbsp;&lt;em&gt;why&lt;/em&gt; this happens, but in general I would suggest keeping the return type as a list if it can return a variable number of results. In some cases it can actually make it harder to manage if your return type is sometimes a list or sometimes a single item. However, if it&amp;#39;s always a list (even if it&amp;#39;s a list of one or zero), then it&amp;#39;s easier to troubleshoot issues and design in a way that lists are supported.&lt;/p&gt;
&lt;p&gt;The case to me where it&amp;nbsp;&lt;em&gt;does&lt;/em&gt; make sense to cast it to a single item (like Mike suggested) is when you know it will always return a single item (or null). For example, if you have a query that filters by the primary key, it&amp;#39;s guaranteed to only return a single item, so you might as well cast the type to a single item as well.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query data</title><link>https://community.appian.com/thread/135470?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 17:22:33 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:4a55bee4-a85b-42ca-9118-e053d759fa5c</guid><dc:creator>Rahul009</dc:creator><description>&lt;p&gt;Yes &lt;a href="/members/mikes0011"&gt;Mike Schmitt&lt;/a&gt;&amp;nbsp;, that&amp;#39;s right.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query data</title><link>https://community.appian.com/thread/135443?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 12:57:00 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1e2a8d0c-d5a6-4eed-adcc-e3b61e08509d</guid><dc:creator>Konduru Chaitanya</dc:creator><description>&lt;p&gt;Okay, got it!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query data</title><link>https://community.appian.com/thread/135442?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 12:55:58 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a89ce7f4-fd6b-432c-ab1b-1795119233f8</guid><dc:creator>Mike Schmitt</dc:creator><description>[quote userid="140649" url="~/discussions/f/new-to-appian/35003/query-data/135440"]That is how it works. I still do not understand your question [/quote]
&lt;p&gt;He&amp;#39;s saying (unless i&amp;#39;m sorely mistaken) that there are some conditions in which a query will return one entry and some in which it returns zero entries, and is confused that the output is still &amp;quot;list type&amp;quot;.&amp;nbsp; Hence my explanation below of how to manually handle this when necessary.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query data</title><link>https://community.appian.com/thread/135440?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 12:53:28 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3fbdde8c-05c7-41a9-90f3-5e8a18c9f203</guid><dc:creator>Konduru Chaitanya</dc:creator><description>&lt;p&gt;Are you trying to say, when you are passing certain fields into the ri!selectionField you get some list and when you don&amp;#39;t pass you are still getting the list?&lt;br /&gt;&lt;br /&gt;If so, That is how it works. I still do not understand your question to be frank.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query data</title><link>https://community.appian.com/thread/135438?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 12:31:21 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:55c65625-3688-440b-91b6-5ed3cf351419</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;let me know if my earlier reply (below) makes any sense.&amp;nbsp; it looks like this is a standard use case, though it&amp;#39;ll depend on exactly what the context is in which you want to force the returned value to not snow up as a list.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query data</title><link>https://community.appian.com/thread/135435?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 12:16:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5892c9d7-7c9a-4df2-9c0c-5b943830af65</guid><dc:creator>Rahul009</dc:creator><description>&lt;p&gt;Below query I am using for diffrent record types&lt;/p&gt;
&lt;pre class="wp-block-preformatted"&gt;a!localVariables(
  local!data: a!queryRecordType(
    recordType: &amp;quot;recordType!HM Patient&amp;quot;,
    fields: ri!selectionField,
    filters: a!queryLogicalExpression(
      logicalExpressions: ri!logicalExpression,
      operator: &amp;quot;AND&amp;quot;,
      filters: {
        a!queryFilter(
          field: &amp;quot;recordType!HM Patient.fields.patientIdPk_int&amp;quot;,
          operator: &amp;quot;=&amp;quot;,
          value: ri!patientIdPk_int
        ),
        a!queryFilter(
          field: &amp;quot;recordType!HM Patient.fields.genderId_int&amp;quot;,
          operator: &amp;quot;=&amp;quot;,
          value: ri!genderId_int
        ),
        ri!filters
      },
      ignoreFiltersWithEmptyValues: true
    ),
    pagingInfo: a!defaultValue(
      value: ri!pagingInfo,
      default: a!pagingInfo(
        startIndex: 1,
        batchSize: 50,
        sort: {
          a!sortInfo(
            field: &amp;quot;recordType!HM Patient.fields.patientIdPk_int&amp;quot;,
            ascending: false()
          )
        }
      )
    ),
    fetchTotalCount: or(ri!fetchTotalCount_bool)
  ),
  if(
    or(ri!returnDataSubset_bool),
    local!data,
    index(local!data, &amp;quot;data&amp;quot;, {})
  )
)&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query data</title><link>https://community.appian.com/thread/135434?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 12:15:50 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2f9887a3-a95e-413b-a719-8e0ef56ca275</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Queried data (of any type, be it record type or entity) is automatically treated as a list (whether single, empty, or list) until you specify otherwise.&lt;/p&gt;
&lt;p&gt;A common way of forcing the output to appear as single is to use the square bracket indexing to specify the first result (which is necessary even if there&amp;#39;s only one) - like [1] after &amp;quot;.data&amp;quot; (being the result of your query).&amp;nbsp; One issue this creates is it&amp;#39;ll break (error) if the query actually returns empty - so instead we use index() for what it&amp;#39;s intended for, i.e. to grab the first index (if any) and specify a default value otherwise...&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;index(local!myQueryResult.data, 1, {})&amp;nbsp; &lt;/strong&gt;&lt;span style="font-size:75%;"&gt;(note: you should replace &amp;quot;{}&amp;quot; here with &amp;quot;null()&amp;quot; to force the output to show up as simply blank instead of an empty list, if desired)&lt;/span&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;and, as always, to avoid confusion and increase code readability, i strongly suggest that you use &lt;strong&gt;&lt;em&gt;property()&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;&lt;/em&gt; to retrieve a specific field instead of &lt;em&gt;index()&lt;/em&gt;, since &amp;quot;index&amp;quot; implies a position in an array, and &amp;quot;property&amp;quot; implies a particular data property.&lt;/p&gt;
&lt;p&gt;As Konduru mentioned already, sharing a code snippet and/or result screenshots would help us specify what you&amp;#39;d need to do in your particular case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query data</title><link>https://community.appian.com/thread/135431?ContentTypeID=1</link><pubDate>Thu, 16 May 2024 11:54:19 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:dbdebe74-b01a-4d8c-bf57-f573fc3e511d</guid><dc:creator>Konduru Chaitanya</dc:creator><description>&lt;p&gt;Please share the code snippet of both your query rule and the interface.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>