QlikView's project (PRJ) folder does not include data, which means that data stored in the QVW file's data model, as well as variable values, are lost when an application is restored from the PRJ folder.
The data in the data model will be restored once the restored QVW file is reloaded. In the same way, variables defined in the load script will be restored.
Variables that have been defined in QlikView desktop client's variable overview section will not be restored as they are not part of the load script.
Resolution:
Variable values are not stored in the project folder XML files, hence it is not possible to recover them if the QVW file gets deleted or corrupted.
To prevent the loss of variable values, the current variables can be exported to a QVD during application reload. The QVD can then later be used to recover the previous variable values.
Store all application variables to QVD file
The below script loads all defined variables from the AllProperties.XML file in the QlikView project (PRJ) folder. This script should be loaded along with the application linked to the PRJ folder, since the variable values are stored in that QVW file. All the variables found in the AllProperties.XML are extracted and stored into a QVD file called Variables.qvd.
To be on the safe side this script could be included all reloads so that the variables can be restored even if the QVW file gets corrupted or deleted.
VariableNames:
LOAD Name AS VariableName
FROM [MyApplication-prj\AllProperties.xml] (XmlSimple, Table is [AllProperties/VariableProperties/VariableProperties]);
FOR i=0 TO NoOfRows('VariableNames')
LET varName = Peek('VariableName', $(i), 'VariableNames');
LET varValue = $(varName);
Variables:
LOAD
'$(varName)' AS VariableName,
'$(varValue)' AS VariableValue
AutoGenerate 1;
NEXT
STORE Variables INTO Variables.qvd (QVD);
DROP Tables VariableNames, Variables;
Restore all application variables from a QVD file
The variables stored in the QVD file in the above example can be restored by the principle below. The QVD is loaded and then the variables are picked out one by one and defined in the application. This script should only be executed on loads where the variables should be recovered.
Variables:
LOAD VariableName,
VariableValue
FROM Variables.qvd (qvd);
FOR i=0 TO NoOfRows('Variables')
LET vVar = Peek('VariableName', $(i), 'Variables');
LET vVal = Peek('VariableValue', $(i), 'Variables');
LET '$(vVar)' = '$(vVal)';
NEXT