Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

omarbensalem
Esteemed Contributor

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
Esteemed Contributor

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

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

17 Replies
MVP
MVP

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

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
Esteemed Contributor

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

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

MVP
MVP

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

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

Highlighted
omarbensalem
Esteemed Contributor

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

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
Esteemed Contributor

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

And ps:

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

Capture.PNG

MVP
MVP

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

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

omarbensalem
Esteemed Contributor

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

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

thechacal
Contributor III

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

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

MVP
MVP

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

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);