Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Conditional Field Load within Script

Hi Community,

I have a quick question, which someone on here is bound to be able to answer.

I am currently attempting to set up a load condition within the script, which only attempts to load a specific field in from a CSV if the value of a variable is over a certain value.

Unfortunately, the logic does not seem to work. The line in question is something basic such as:

if('$(FEEDLEVEL)' > '3.1',[Job Number],'??') as JobNumber

Where FEEDLEVEL equals a decimal number.

The purpose of this condition is that we have a number of different feed levels. In some feeds, the field 'Job Number' will be present; and in some it won't be.

When I attempt to run a reload on the script with the above defined and the FEEDLEVEL variable set to '3.1', I get an error "Field not found - <Job Number>".

I have also tried the below, but the script still complains about not being able to find 'Job Number', even when the value of FEEDLEVEL is set to something like '2':

if(wildmatch('$(FEEDLEVEL)','1*','2*','3.1'),'??', [Job Number]) as JobNumber

Please can somebody help me on this. Hopefully I've explained things ok.

Thanks

Jacob

1 Solution

Accepted Solutions
Not applicable
Author

Right, for anyone out there that might wish to do something similar, the solution is very simple. Declare a new String variable for the desired field, which will be instantiated with either value based on the appropriate condition.

For example:

if '$(FEEDLEVEL)' > '3.1' then

     set JobNumber = "[Job Number]";

else

     set JobNumber = "'??'";

end if

LOAD ...

     $(JobNumber) as JobNumber

FROM ...

View solution in original post

5 Replies
brenner_martina
Partner - Specialist II
Partner - Specialist II

Hi, Jacob,

why do you work with strings? It is better using numbers. If necessary you can use the function Num#() to interpret the numbers.

In Load-Statement:

If(FEEDLEVEL>3.1,[Job Numer],'??') As JobNumber

but if you want to load only some data use this:

Load [Job Number] As JobNumber,

     ...

From tablename.csv (...)

Where FEEDLEVEL>3.1;

erichshiino
Partner - Master
Partner - Master

Hi, Jacob

is [Job Number] part of your original table? I`m asking because after this you rename it to JobNumber

Maybe your syntax would be like this:

if('$(FEEDLEVEL)' > '3.1',JobNumber,'??') as JobNumber

And then you can apply Martina`s recommendation about number comparison

Rgds,

Erich

Not applicable
Author

Hi Brenner and Erich. Thanks for your replies.

The reason that I used this syntax is that when declaring FEEDLEVEL as you suggest, the script interprets this as a field within the csv.

I have also tried using Num# as you suggest to convert the string to a number. This doesn't work either. This field needs to be loaded in conditionally within the main table load to elimate issues with indexing.

Erich, in answer to your question [Job Number] is a field within a csv, which can be present or not depending on the level of feed that we are using. If we are using a feed level where [Job Number] does not appear in the csv, we want to ignore it (i.e. populate that field with '??'); otherwise, we want it adding to the table.

[Job Number] is not loaded into a table prior to this.

Thanks again,

Jacob

Not applicable
Author

Right, for anyone out there that might wish to do something similar, the solution is very simple. Declare a new String variable for the desired field, which will be instantiated with either value based on the appropriate condition.

For example:

if '$(FEEDLEVEL)' > '3.1' then

     set JobNumber = "[Job Number]";

else

     set JobNumber = "'??'";

end if

LOAD ...

     $(JobNumber) as JobNumber

FROM ...

tejes
Contributor III
Contributor III

Hi, 

Do we need to set this if condition before the load statement or inside the load statement