Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I just created 500 variables to test some issues (in the data load editor),
and now I see the name and the value stay in the cache of the app even if I remove the script who create them,
anyone can tell me how can I delete them from my app?
Thanks
Hi @marcus_sommer ,
As Rob and I discussed above, that method does not work in Qlik Sense. R&D has confirmed that there was a conscious decision to change the way variables worked in Qlik Sense due to scalability reasons.
Hi @MendyS ,
You can using the APIs, yes. The easiest way to do this is using the Qlik-CLI. This utility works for both Qlik Cloud and Qlik Sense Enterprise Client-Managed, however the script below was built for Qlik Cloud. If you are using Qlik Sense Enterprise Client-Managed, it will need to be modified (i.e., it would likely be easier to do steps 1-4 below manually and just use the variable removal section which should be pretty much the same across platforms).
In essence, this is the flow:
1. Get the current load script of the app and save it to a file.
2. Set the load script of the app to `exit script;`.
3. Reload the app to make all of the script variables non-script variables so that they can be deleted.
4. Reset the script to the original.
5. Get a list of all variables.
6. Delete each variable (only saving on the last -- this speeds things up dramatically).
The script I've included below does this process automatically. Just set the app Id. Note that you will still have to delete the variables in the script manually from your script of course before you reload the app again.
$app = '<your-appId-here>';
$OutputEncoding = [Console]::InputEncoding = [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding;
$script = qlik app script get -a $app;
Set-Content -Path "current_script.qvs" -Value $script;
Set-Content -Path "empty_script.qvs" -Value 'exit script;'
qlik app script set ./empty_script.qvs -a $app;
$reloadId = (qlik reload create --appId $app | ConvertFrom-Json).id;
$status = $null;
while ($status -ne 'SUCCEEDED') {
Start-Sleep -Seconds 3;
$status = (qlik reload get $reloadId | ConvertFrom-Json).status;
}
qlik app script set ./current_script.qvs -a $app;
$vars = qlik app variable ls -a $app --json | ConvertFrom-Json;
$i = 1;
foreach ($var in $vars) {
if ($i -ne $vars.length) {
qlik app variable rm $var.title -a $app --no-save;
}
else {
qlik app variable rm $var.title -a $app;
}
$i += 1;
}
Remove-Item -Path "empty_script.qvs";
Note that I do not remove the `current_script.qvs` file so you don't lose your original script in case it does not work for whatever reason. I would suggest running the script on a duplicated copy of the app to be safe.
Cheers,
Set them to empty at the end of the script.
SET var1=;
SET var2=;
etc
-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com
Hey @rwunderlich ,
What am I missing? I have seen that posted numerous times on Qlik Community, but it has never worked for me. Was this a QlikView relic, or is there a trick I'm missing? All that does is make them non-script variables in Qlik Sense, but it does not delete them in any of my tests.
Cheers,
@rwunderlich -- Ah, I see. That only works if the variable didn't already exist in the app, which in the case above, they all do. From what I've seen, its almost always the case that users want to delete variables that already exist, not prevent them from being created.
@Daniel_Pilla It looks more like "what am I missing". I wasn't aware that no longer worked in Qlik Sense. Yes, it worked in QV, and I believe it worked at one time in QS. I don't know if this is a bug or a side effect of the script/non-script variable thing. I'm gonna go with "bug" because it does not makes sense to convert them to non-script vars when they are empty. 🙂
-Rob
Hey @rwunderlich ,
Interesting, I've never seen it work in QS. Here is a post from @jonathandienst in 2016 about this same topic stating that it only worked with variables that weren't yet created, so I'm not sure when that was the case: https://community.qlik.com/t5/QlikView-App-Dev/Remove-Variables-From-Script/m-p/1059775/highlight/tr... -- I will ping PM/R&D just to see because now I'm curious! Haha.
Hi @rwunderlich
Thanks for the answer, I think that I have not explained enough, so I will try to explain it in another way.
I have app 'x', I am testing some logic and I add a new tab in the data load editor,
for example -
This loop -
for i = 0 to 1000
let $(i) = $(i);
next
now I remove the loop and I still see in the cache the 5000 vars,
I can't add 5000 rows to empty all the vars, I try to find other way.
(I don't know the names of the 5000 vars, the names came from another way).
Thanks
@Daniel_Pilla
I will try it soon and let you know,
Thanks
You could delete the variables in the same way you have created them - just by:
for i = 0 to 1000
let $(i) = null();
next