<?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>article Conditional reload based on QVD update time in Official Support Articles</title>
    <link>https://community.qlik.com/t5/Official-Support-Articles/Conditional-reload-based-on-QVD-update-time/ta-p/1764531</link>
    <description>&lt;P class="lia-align-left"&gt;It may be desirable to reload an app depending on whether all QVD files have been updated since the previous app reloaded. Below is an example of how this can be accomplished in the load script by comparing the last updated timestamp of QVD files with the app's previous reload time.&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;Environment&lt;/H4&gt;
&lt;UL&gt;
&lt;LI&gt;Qlik Sense Enterprise SaaS&lt;/LI&gt;
&lt;LI&gt;Qlik&amp;nbsp;Sense Enterprise on Windows&lt;/LI&gt;
&lt;LI&gt;Qlik&amp;nbsp;Sense Desktop&lt;/LI&gt;
&lt;LI&gt;QlikView Server&lt;/LI&gt;
&lt;LI&gt;QlikView Desktop&lt;/LI&gt;
&lt;/UL&gt;
&lt;H4&gt;Previous successful app reload time&lt;/H4&gt;
&lt;P&gt;The simplest way to track the previous reload of an app is to store the current time in a variable at the end of the script execution. This variable value will only be set if the script execution successfully reaches the end and will be available for the following execution as a reference of the previous successful reload.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;LET vPrevReload = UTC();&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At the first reload of the app, the variable will not exist, meaning it is of zero length. In this case, it makes sense to initiate a really old timestamp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;IF Len($(#vPrevReload)) = 0 THEN
    LET vPrevReload = Date(0);
ENDIF    &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;QVD created time&lt;/H4&gt;
&lt;P&gt;QVD files always have an XML header representing metadata of its data content. QVD files are&amp;nbsp;never updated when data changes. They are always overwritten when a STORE command is executed. For this reason, the XML header contains a field called&amp;nbsp;CreateUtcTime, which is the time when the file was written or created.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is possible to determine if the QVD file has been updated since the previous app reload by comparing the QVD created time with the previous reload variable. For simplicity, we flag the comparison result with a 1 when the file has been updated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;QvdFiles:
LOAD
    If(CreateUtcTime &amp;gt; $(#vPrevReload), 1, 0) AS IsUpdatedFromPrevReload
FROM [lib://MyFolder/MyDataFile.qvd]
(XmlSimple, table is QvdTableHeader);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;Checking multiple QVD files&lt;/H4&gt;
&lt;P&gt;Most apps are dependent on data from more than one QVD file. To check if multiple files have been updated, the files need to be named, for example, by simply listing the file path in an inline table. Notice, the path is a complete data folder connection reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;QvdSource:
LOAD @1 AS Qvd Inline [
lib://MyFolder/MyDataFile1.qvd
lib://MyFolder/MyDataFile2.qvd
lib://MyFolder/MyDataFile3.qvd
] (txt, no labels);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By iterating the timestamp comparison over all the QVD files, it is possible to decide if all files have been updated since the previous reload. This is done in two steps, first generate a comparison for each file, then aggregate the total result. The aggregated sum of all comparison results will represent how many files have been updated since the individual results are 1 when a file has been updated.&lt;/P&gt;
&lt;P&gt;An aggregation of a data set in the load script requires grouping data by a field. For this reason, a dummy value that is the same for all records is introduced to create a single group of all records.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;For Each vQvdFile in FieldValueList('Qvd')
    QvdFiles:
    LOAD
        'All Files' AS GroupByAll,
    	'$(vQvdFile)' AS QvdFile,
        If(CreateUtcTime &amp;gt; $(#vPrevReload), 1, 0) AS IsUpdatedFromPrevReload
    FROM [$(vQvdFile)]
    (XmlSimple, table is QvdTableHeader);
Next

NoOfUpdatedQvds:
LOAD 
    Sum(IsUpdatedFromPrevReload) AS NoOfUpdatedQvd
Resident QvdFiles
Group By GroupByAll;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;Failing the reload&lt;/H4&gt;
&lt;P&gt;The total number of QVD files is expected to be the same as the number of updated files if the app should be reloaded. If the two values are different, then the reload should be avoided.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Important to notice that the reload must fail for the app to remain in its current state with data from the previous successful reload. This will allow a business user to keep consuming the app, even though the data might become a bit aged.&lt;BR /&gt;&lt;SPAN&gt;A simple way to fail a reload is to load from a non-existing data source, for example, by targeting a data connection that is unlikely to exist. Even if the data connection would exist, the load statement will fail by &lt;U&gt;not&lt;/U&gt; specifying a target data file.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;LET vUpdatedCount = Peek('NoOfUpdatedQvd', 0, 'NoOfUpdatedQvds');

IF $(#vUpdatedCount) &amp;lt;&amp;gt; NoOfRows('QvdSource') THEN
    LOAD *
    FROM lib://QvdFilesAreNotUpdated/ (QVD);
ENDIF    
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="font-style: italic;"&gt;The information in this article is provided as-is and to be used at own discretion. Depending on tool(s) used, customization(s), and/or other factors ongoing support on the solution below may not be provided by Qlik Support.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Apr 2024 13:44:32 GMT</pubDate>
    <dc:creator>ToniKautto</dc:creator>
    <dc:date>2024-04-17T13:44:32Z</dc:date>
    <item>
      <title>Conditional reload based on QVD update time</title>
      <link>https://community.qlik.com/t5/Official-Support-Articles/Conditional-reload-based-on-QVD-update-time/ta-p/1764531</link>
      <description>&lt;P class="lia-align-left"&gt;It may be desirable to reload an app depending on whether all QVD files have been updated since the previous app reloaded. Below is an example of how this can be accomplished in the load script by comparing the last updated timestamp of QVD files with the app's previous reload time.&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;Environment&lt;/H4&gt;
&lt;UL&gt;
&lt;LI&gt;Qlik Sense Enterprise SaaS&lt;/LI&gt;
&lt;LI&gt;Qlik&amp;nbsp;Sense Enterprise on Windows&lt;/LI&gt;
&lt;LI&gt;Qlik&amp;nbsp;Sense Desktop&lt;/LI&gt;
&lt;LI&gt;QlikView Server&lt;/LI&gt;
&lt;LI&gt;QlikView Desktop&lt;/LI&gt;
&lt;/UL&gt;
&lt;H4&gt;Previous successful app reload time&lt;/H4&gt;
&lt;P&gt;The simplest way to track the previous reload of an app is to store the current time in a variable at the end of the script execution. This variable value will only be set if the script execution successfully reaches the end and will be available for the following execution as a reference of the previous successful reload.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;LET vPrevReload = UTC();&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At the first reload of the app, the variable will not exist, meaning it is of zero length. In this case, it makes sense to initiate a really old timestamp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;IF Len($(#vPrevReload)) = 0 THEN
    LET vPrevReload = Date(0);
ENDIF    &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;QVD created time&lt;/H4&gt;
&lt;P&gt;QVD files always have an XML header representing metadata of its data content. QVD files are&amp;nbsp;never updated when data changes. They are always overwritten when a STORE command is executed. For this reason, the XML header contains a field called&amp;nbsp;CreateUtcTime, which is the time when the file was written or created.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is possible to determine if the QVD file has been updated since the previous app reload by comparing the QVD created time with the previous reload variable. For simplicity, we flag the comparison result with a 1 when the file has been updated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;QvdFiles:
LOAD
    If(CreateUtcTime &amp;gt; $(#vPrevReload), 1, 0) AS IsUpdatedFromPrevReload
FROM [lib://MyFolder/MyDataFile.qvd]
(XmlSimple, table is QvdTableHeader);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;Checking multiple QVD files&lt;/H4&gt;
&lt;P&gt;Most apps are dependent on data from more than one QVD file. To check if multiple files have been updated, the files need to be named, for example, by simply listing the file path in an inline table. Notice, the path is a complete data folder connection reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;QvdSource:
LOAD @1 AS Qvd Inline [
lib://MyFolder/MyDataFile1.qvd
lib://MyFolder/MyDataFile2.qvd
lib://MyFolder/MyDataFile3.qvd
] (txt, no labels);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By iterating the timestamp comparison over all the QVD files, it is possible to decide if all files have been updated since the previous reload. This is done in two steps, first generate a comparison for each file, then aggregate the total result. The aggregated sum of all comparison results will represent how many files have been updated since the individual results are 1 when a file has been updated.&lt;/P&gt;
&lt;P&gt;An aggregation of a data set in the load script requires grouping data by a field. For this reason, a dummy value that is the same for all records is introduced to create a single group of all records.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;For Each vQvdFile in FieldValueList('Qvd')
    QvdFiles:
    LOAD
        'All Files' AS GroupByAll,
    	'$(vQvdFile)' AS QvdFile,
        If(CreateUtcTime &amp;gt; $(#vPrevReload), 1, 0) AS IsUpdatedFromPrevReload
    FROM [$(vQvdFile)]
    (XmlSimple, table is QvdTableHeader);
Next

NoOfUpdatedQvds:
LOAD 
    Sum(IsUpdatedFromPrevReload) AS NoOfUpdatedQvd
Resident QvdFiles
Group By GroupByAll;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;Failing the reload&lt;/H4&gt;
&lt;P&gt;The total number of QVD files is expected to be the same as the number of updated files if the app should be reloaded. If the two values are different, then the reload should be avoided.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Important to notice that the reload must fail for the app to remain in its current state with data from the previous successful reload. This will allow a business user to keep consuming the app, even though the data might become a bit aged.&lt;BR /&gt;&lt;SPAN&gt;A simple way to fail a reload is to load from a non-existing data source, for example, by targeting a data connection that is unlikely to exist. Even if the data connection would exist, the load statement will fail by &lt;U&gt;not&lt;/U&gt; specifying a target data file.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;LET vUpdatedCount = Peek('NoOfUpdatedQvd', 0, 'NoOfUpdatedQvds');

IF $(#vUpdatedCount) &amp;lt;&amp;gt; NoOfRows('QvdSource') THEN
    LOAD *
    FROM lib://QvdFilesAreNotUpdated/ (QVD);
ENDIF    
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="font-style: italic;"&gt;The information in this article is provided as-is and to be used at own discretion. Depending on tool(s) used, customization(s), and/or other factors ongoing support on the solution below may not be provided by Qlik Support.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 13:44:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Official-Support-Articles/Conditional-reload-based-on-QVD-update-time/ta-p/1764531</guid>
      <dc:creator>ToniKautto</dc:creator>
      <dc:date>2024-04-17T13:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional relaod based on QVD update time</title>
      <link>https://community.qlik.com/t5/Official-Support-Articles/Conditional-reload-based-on-QVD-update-time/tac-p/2433444#M13573</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Thanks for sharing this qvf file. If I need to reload data only when the number of QVD records changes.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;How would I change this script? Please help.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 19:04:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Official-Support-Articles/Conditional-reload-based-on-QVD-update-time/tac-p/2433444#M13573</guid>
      <dc:creator>olgaavalos</dc:creator>
      <dc:date>2024-03-21T19:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional relaod based on QVD update time</title>
      <link>https://community.qlik.com/t5/Official-Support-Articles/Conditional-reload-based-on-QVD-update-time/tac-p/2434193#M13596</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/149046"&gt;@olgaavalos&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For detailed assistance with customizing scripts and achieving specific needs, please post your requirements directly in the&amp;nbsp;&lt;STRONG&gt;&lt;A href="https://community.qlik.com/t5/App-Development/bd-p/qlik-sense-app-development" target="_blank" rel="noopener"&gt;Qlik App Development&lt;/A&gt;&amp;nbsp;&lt;/STRONG&gt;forum, where our active support agents and your knowledgeable Qlik peers can assist you.&lt;/P&gt;
&lt;P&gt;All the best,&lt;BR /&gt;Sonja&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2024 10:28:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Official-Support-Articles/Conditional-reload-based-on-QVD-update-time/tac-p/2434193#M13596</guid>
      <dc:creator>Sonja_Bauernfeind</dc:creator>
      <dc:date>2024-03-25T10:28:51Z</dc:date>
    </item>
  </channel>
</rss>

