Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

tkendrick20
Valued Contributor

Qlik Sense Script Line Error on For Loop in Version 2.2.0

I have a script that used to work with previous versions and definitely worked in QlikView:

[tmpTable]:

Generic Load * Resident [Demographic Responses];

[Demographic Information]:

Load Distinct [Respondent ID] as [Respondent ID]

Resident [Demographic Responses];

FOR i = 0 to NoOfTables()

TableList:

  Load TableName($(i)) as [TableName] AUTOGENERATE 1

  WHERE WildMatch (TableName($(i)), 'tmpTable.*');

NEXT i

FOR i = 1 to FieldValueCount('Tablename')

  LET vTable = FieldValue('Tablename', $(i));

  LEFT JOIN ('Demographic Information') LOAD * RESIDENT [$(vTable)];

  DROP TABLE [$(vTable)];

NEXT i

Drop Tables [Demographic Responses], TableList;

The first For loop works, but the second does not for some reason. I assure you there is NO problem with the data in [Demographic Responses]. I've tried other types of loops and I am out of ideas. I get the following error every time:

Qlik Sense Line Error.PNG

6 Replies

Re: Qlik Sense Script Line Error on For Loop in Version 2.2.0

Load TableName($(i)) as [TableName] AUTOGENERATE 1 

FOR i = 1 to FieldValueCount('Tablename')

TableName and Tablename are two different fields. So, just a typo.

sureshqv
Esteemed Contributor III

Re: Qlik Sense Script Line Error on For Loop in Version 2.2.0

Missing Capital "N"   in ur TableName

u shud use the same fieldnames or table names same for entire document.

tkendrick20
Valued Contributor

Re: Qlik Sense Script Line Error on For Loop in Version 2.2.0

That has been corrected, still the same error. I was testing a bunch of different things which is why that mistake is in the original question. I have also tried:

  • While -> Loop instead of For -> Next
  • Doing  "FieldValueCount('Tablename') STEP 1"
  • The table names include spaces which I replaced with "_"

In debugging I'm seeing some weird things happen where the variable "i" is exceeding the actual count of field values and then the loop is breaking. I'll keep at it

Re: Qlik Sense Script Line Error on For Loop in Version 2.2.0

I saw you read another similar discussion. Did you enable the legacy mode as mentioned in that discussion?

tkendrick20
Valued Contributor

Re: Qlik Sense Script Line Error on For Loop in Version 2.2.0

I have not. This is Qlik Sense server I'm working on. Does it still work with that?

Re: Qlik Sense Script Line Error on For Loop in Version 2.2.0

Yes, unfortunately it's a server wide setting. And it has security implications so this is not a step to take lightly. See Qlik Sense Legacy mode for more information.