Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
chris_br
Contributor
Contributor

Generate script

Is there a way to generate script from a variable ?

case:

field A contains 'load field1 as field_1'

variable  = fieldvalue(fieldA)

how do I get this in the script ? I tried

$(variable)  from table;

but when loading this is the result:

fieldvalue(fieldA)  from table;

Labels (1)
2 Solutions

Accepted Solutions
Or
MVP
MVP

You would presumably use the first one.

This works fine as well:

Load * INLINE [
Field
Load 1 as field2 autogenerate(1)
];

Let SomeVariable = FieldValue('Field',1);

$(SomeVariable);

When doing this sort of thing, I'd recommend using debug mode to look at how the variables are getting populated and read.

View solution in original post

marcus_sommer

By using field- or table-functions the names must be wrapped with single-quotes like:

let variable  = fieldvalue('fieldA', 1);

and the appropriate index-value must be specified.

Further the field-values mustn't be wrapped with any quotes but they must contain the appropriate quoting for values and field-names, like:

load 'String' as [new field], FieldX as "FieldY"

and then you could use it like you did:

table: $(variable) from Source;

View solution in original post

6 Replies
Or
MVP
MVP

This works fine:

set SomeVariable = 'Load 1 as field autogenerate(1)';

$(SomeVariable);

 

chris_br
Contributor
Contributor
Author

yes, it works when the variable is hardcoded.

But in this case the field contains the script, and when I define the variable to read the fieldvalue, it doesnt put this in the script, only the definition of the variable.

it puts 'fieldvalue(fieldA)' iso 'load field1 as field_1'

Or
MVP
MVP

Sounds like you haven't defined your variable correctly, then... perhaps you used SET where you should have used LET? You didn't include the actual code so it's hard to say.

chris_br
Contributor
Contributor
Author

I've tried several ways.

So I'm searching for the way to do it right
do I use let or set, with = or not ?
e.g.
let variable  = fieldvalue(fieldA);
set variable  = fieldvalue(fieldA);
set variable  = =fieldvalue(fieldA);
or something else ?
 
 
Or
MVP
MVP

You would presumably use the first one.

This works fine as well:

Load * INLINE [
Field
Load 1 as field2 autogenerate(1)
];

Let SomeVariable = FieldValue('Field',1);

$(SomeVariable);

When doing this sort of thing, I'd recommend using debug mode to look at how the variables are getting populated and read.

marcus_sommer

By using field- or table-functions the names must be wrapped with single-quotes like:

let variable  = fieldvalue('fieldA', 1);

and the appropriate index-value must be specified.

Further the field-values mustn't be wrapped with any quotes but they must contain the appropriate quoting for values and field-names, like:

load 'String' as [new field], FieldX as "FieldY"

and then you could use it like you did:

table: $(variable) from Source;