Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
OmarBenSalem

Put all the values of a field into a variable (loop maybe?)

Hi guys, stalwar1

Suppose I have a table containg a field Alert:

load Alert inline [

Alert

alert1

alert2

alert3

];

How to do to store all of the alerts (alert1, alert2 and alert3) into a variable?

the goal is to store all this values ito a database as a final objectif; for this, I want to be able to loop all the alerts one by one, and everytime store one value into the destination column, till all the values are stored.

Hope my question is clear enough?

1 Solution

Accepted Solutions
OmarBenSalem
Author

Try it like this Sunny ! It works !

alerts:

load Alert inline [

Alert

alert1

alert2

alert3

];

FOR Each a in FieldValueList('Alert')

dim:

let vAlert = a;

LOAD '$(vAlert)'  as Alerts AutoGenerate 1;

Store dim into [lib://OBS/class.txt] (txt);

NEXT a

View solution in original post

17 Replies
sunny_talwar

May be like this

load Alert inline [

Alert

alert1

alert2

alert3

];

For i = 1 to FieldValueCount('Alert')

     LET vAlert$(i) = FieldValue('Alert', $(i));

NEXT i;

OmarBenSalem
Author

what to do to store it in a txt file for example?

when I exactly copy your script and then do as follow, I have this answer

Table: 

LOAD $(vAlert$(i)) as [Variable Value] 

AutoGenerate 1; 

 

STORE [Variable Value] FROM Table INTO [lib://OBS/class.txt]

(txt);

Capture.PNG

sunny_talwar

You can store a table, not a variable value... what exactly are you trying to do?

OmarBenSalem
Author

I want to be able to store alerts from qlik sense into a database table ; I'm inspired by this:

Capture.PNG

so what I'm trying to do, is to store all the values (all the alerts) into the variable, and then call the procedure to each time store an alert.

I see that he's using a variable vCompany, that's why I thought about using variables.

Hope this was clear..

OmarBenSalem
Author

And ps:

I see here that It's possible to store a variable into a table:

Capture.PNG

sunny_talwar

This is out of my league Omar...  I won't be able to help you with this brother

OmarBenSalem
Author

when I tried this:

alerts:

load Alert inline [

Alert

alert1

alert2

alert3

];

For i = 1 to FieldValueCount('Alert')

     LET vAlert  = FieldValue('Alert', $(i));

Table: 

//LOAD $(vAlert) as [Variable Value] AutoGenerate 1 ;

load FieldValue('Alert', $(i)) as alert resident alerts; 

STORE  alert FROM Table INTO [lib://OBS/class.txt]

(txt);

NEXT i;

each alert is stored 3 times; (problem with the loop logic)

but when I try it with variable instead; I have this:

Capture.PNG

MarcoARaymundo
Creator III
Creator III

Try -> Concat(FieldName, ',')          as FieldNameList

sunny_talwar

You can store a variable into a table, but you can store a table into a txt file like this

Table:

LOAD $(vAlert$(i)) as [Variable Value]

AutoGenerate 1;

STORE Table FROM Table INTO [lib://OBS/class.txt]

(txt);

But this is not possible

Table:

LOAD $(vAlert$(i)) as [Variable Value]

AutoGenerate 1;

STORE [Variable Value] FROM Table INTO [lib://OBS/class.txt]

(txt);