Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Customer & Partners, DEC. 9, 11 AM ET: Qlik Product & Strategy Roadmap Session: Data Analytics REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
ajipaul02
Contributor II
Contributor II

STRANGE issue between two versions of QlikView Desktop

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

2 Replies
ajipaul02
Contributor II
Contributor II
Author

Anyone? please 🙂

petter
Partner
Partner

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....

  1. FieldValueCount() function counts the number of distinct field values for a single field - not related to the table where the field appears. So you might be lucky that all the QUESTION values are distinct.
  2. Even if your QUESTION values are distinct the other fields might not. So you might get fieldnames and fieldvalues that are out of synch with your question... buggy code. So it all depends on the input data whether it will work or not...

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