Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I am facing a STRANGE issue between two versions of QlikView Desktop
The following code executes just fine in 12.10.20100.0 SR3. But SECTION B is NOT being executed in 12.20.20500.0 SR4
//…………………………………………………………… SECTION A
//many lines of script
//……………………………………………………………
For i=1 to FieldValueCount('QUESTION')
let vFieldName=FieldValue('QID',$(i));
let vField = FieldValue('Field',$(i));
RENAME Field [$(vField)] to [$(vFieldName)];
NEXT
//…………………………………………………………… SECTION B
//many lines of script
//……………………………………………………………
Interestingly, if I add one line of code before "NEXT" statement, it executes SECTION B without any problems
example:
For i=1 to FieldValueCount('QUESTION')
let vFieldName=FieldValue('QID',$(i));
let vField = FieldValue('Field',$(i));
RENAME Field [$(vField)] to [$(vFieldName)];
let j = 5; // temp fix
NEXT
Would someone please help me understand this behaviour?
Thanks,
Aji
Anyone? please 🙂
What you are doing in this FOR loop is risky code and the problem might not at all be related to the Qlik Sense Desktop version.
I learned it the hard way myself by struggling with FieldValue() and FieldCount() and getting what I thought then was the wrong answers until I discovered that these functions relate to a single field and a field in Qlik is always stored with distinct values and it's only in the table structures that they are non-distinct. This is very important to understand but unfortunately the current Qlik documentation online does not make this very clear at all.
Let me explain which issues you can get into....
The way to approach it is to use the Peek() function which DOES relate to the row number of the table.
So let's say your table is named QUESTIONS then you could code like this:
FOR i=1 TO NoOfRows('QUESTIONS')
vFieldName=Peek('QID',i, 'QUESTIONS');
vField = Peek('Field',i, 'QUESTIONS');
RENAME FIELD [$(vField)] TO [$(vFieldName)];
NEXT