<?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 get a count of database rows in Appian web api</title><link>https://community.appian.com/discussions/f/integrations/18222/how-to-get-a-count-of-database-rows-in-appian-web-api</link><description>I am trying to write a custom web-api in Appian that will [among other things] return a count of the number of rows in a database table. To that end, I have added this local variable in my api code. 
 local!countOfRows: a!queryEntity(
 entity: cons!MY_DATABASE_TABLE_DS</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to get a count of database rows in Appian web api</title><link>https://community.appian.com/thread/71694?ContentTypeID=1</link><pubDate>Thu, 30 Jan 2020 01:08:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2f6db0d0-972a-46bd-b630-10640a6f670f</guid><dc:creator>davidb545</dc:creator><description>&lt;p&gt;thanks heaps for the tip! :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a count of database rows in Appian web api</title><link>https://community.appian.com/thread/71680?ContentTypeID=1</link><pubDate>Wed, 29 Jan 2020 15:15:51 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9d99f924-0258-4059-8801-9d2ac2313f8e</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;As an aside, you should&amp;nbsp;&lt;strong&gt;definitely not&lt;/strong&gt; use the batchsize of &amp;quot;-1&amp;quot; when just getting the .totalCount, as this&amp;nbsp;&lt;em&gt;returns all rows&lt;/em&gt; in the query, which you would then proceed to ignore.&amp;nbsp; Instead, use a batch size of &amp;quot;0&amp;quot;, as this actually pulls the metadata (including totalCount) without doing the work of returning all rows.&amp;nbsp; This will be significantly better for performance.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a count of database rows in Appian web api</title><link>https://community.appian.com/thread/71677?ContentTypeID=1</link><pubDate>Wed, 29 Jan 2020 07:08:56 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d6d47979-2ced-4a91-9d88-b9d474003c66</guid><dc:creator>davidb545</dc:creator><description>&lt;p&gt;Ok - I have got the code working now - the final code is this:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;with( &lt;br /&gt; local!entities: a!queryEntity(&lt;br /&gt; entity: cons!MY_DATABASE_TABLE_DS,&lt;br /&gt; query: a!query(&lt;br /&gt; pagingInfo: a!pagingInfo(&lt;br /&gt; startIndex: 1,&lt;br /&gt; batchSize: 10&lt;br /&gt; )&lt;br /&gt; ),&lt;br /&gt; fetchTotalCount: true&lt;br /&gt; ).totalCount, &lt;br /&gt; a!httpResponse( &lt;br /&gt; headers: {&lt;br /&gt; a!httpHeader(name: &amp;quot;Content-Type&amp;quot;, value: &amp;quot;application/json&amp;quot;)&lt;br /&gt; },&lt;br /&gt; body: a!toJson({count: local!entities})&lt;br /&gt; )&lt;br /&gt;)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The only difference was that I added a batch size of 10.&amp;nbsp; It [nevertheless] returns the correct number of rows in the database...&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;thanks heaps for your help.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;David :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a count of database rows in Appian web api</title><link>https://community.appian.com/thread/71676?ContentTypeID=1</link><pubDate>Wed, 29 Jan 2020 07:04:39 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:21126214-768b-46bb-99dc-5ce4f60a2b6c</guid><dc:creator>davidb545</dc:creator><description>&lt;p&gt;Thanks Ekansh - I have updated the code to this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;with( &lt;br /&gt; local!entities: a!queryEntity(&lt;br /&gt; entity: cons!MY_DATABASE_TABLE_DS,&lt;br /&gt; query: a!query(&lt;br /&gt; pagingInfo: a!pagingInfo(&lt;br /&gt; startIndex: 1,&lt;br /&gt; batchSize: -1&lt;br /&gt; )&lt;br /&gt; ),&lt;br /&gt; fetchTotalCount: true&lt;br /&gt; ).totalCount, &lt;br /&gt; a!httpResponse( &lt;br /&gt; headers: {&lt;br /&gt; a!httpHeader(name: &amp;quot;Content-Type&amp;quot;, value: &amp;quot;application/json&amp;quot;)&lt;br /&gt; },&lt;br /&gt; body: a!toJson({count: local!entities})&lt;br /&gt; )&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;However, it still shows error 500.&amp;nbsp; I am wondering if there is too much data? There are about 7000 rows in the relevant database table - so I wouldn&amp;#39;t have thought it was too big - do you think it is?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;cheers,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;David.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a count of database rows in Appian web api</title><link>https://community.appian.com/thread/71675?ContentTypeID=1</link><pubDate>Wed, 29 Jan 2020 06:48:20 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f52a4148-faf5-41b4-a11e-348e64db6f44</guid><dc:creator>ekanshj</dc:creator><description>&lt;p&gt;Hi &lt;a href="/members/davidb545"&gt;davidb545&lt;/a&gt;&lt;br /&gt;You need to change the way you pass the body of the response&lt;br /&gt;&lt;img src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/18/pastedimage1580280507730v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a count of database rows in Appian web api</title><link>https://community.appian.com/thread/71674?ContentTypeID=1</link><pubDate>Wed, 29 Jan 2020 06:31:54 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:665cd9bd-78ad-40bf-b75a-24602a90ad63</guid><dc:creator>davidb545</dc:creator><description>&lt;p&gt;I have [also] tried writing a seperate api which [only] returns the row-count for my entity, but it [also] returns error 500...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;a!localVariables(
  local!entities: a!queryEntity(
    entity: cons!MY_DATABASE_TABLE_DS,
    query: a!query(
      pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: -1
      )
    ),
    fetchTotalCount: true
  ).totalCount,
  a!httpResponse(
        headers: {
      a!httpHeader(name: &amp;quot;Content-Type&amp;quot;, value: &amp;quot;application/json&amp;quot;)
    },
    body: a!toJson(value: local!entities)
  )
)&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>