Qlik Community

Qlik Sense App Development

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

crissaegrim
New Contributor III

In a reload script and reload task, raise exception if "0 lines fetched"

Hi.  How can I raise an exception if I have a "0 lines fetched" during any point in the reload task?

2016-11-30 08:00:06 0104 FROM [myDatabase].[dbo].[myTransactionsTable]

2016-11-30 08:00:06 0105 WHERE TranType IN (

2016-11-30 08:00:06 0106 'buy'

2016-11-30 08:00:06 0107 ,'sell'

2016-11-30 08:00:06 0108 )

2016-11-30 08:00:06 0109 AND InvCode NOT LIKE '%collateral%'

2016-11-30 08:00:06 0110

2016-11-30 08:00:06 0111 ORDER BY TDate DESC

2016-11-30 08:00:07      30 fields found: *** OMITTED FOR BREVITY ***

2016-11-30 08:00:07      0 lines fetched

1 Solution

Accepted Solutions

Re: In a reload script and reload task, raise exception if "0 lines fetched"

The only way to raise an exception is to introduce an intentional syntax error like this:

IF NoOfRows('TableName')=0 THEN

    Failing due to no rows;

ENDIF

The "Failing due to no rows" is an invalid statement, but it will nicely show as the error cause as well.

-Rob

5 Replies

Re: In a reload script and reload task, raise exception if "0 lines fetched"

Hi Khoa, the function NoOfRows('TableName') returns the number of rows, you can check if it's equal to zero.

crissaegrim
New Contributor III

Re: In a reload script and reload task, raise exception if "0 lines fetched"

How do I then raise an exception?  Thus marking reload task as failure?

Re: In a reload script and reload task, raise exception if "0 lines fetched"

Hi Khoa, you can finish the reload with "Exit Script;" Is this what you want?

You can use it like:

Exit script when NoOfRows('TableName')=0

or:

IF NoOfRows('TableName')=0 THEN

Exit Script;

ENDIF

crissaegrim
New Contributor III

Re: In a reload script and reload task, raise exception if "0 lines fetched"

Would Exit Script; cause the task to end in failure in QMC?  Because this is what I want.  I need an easy way to, at a glance, tell fail from success of my tasks.

Re: In a reload script and reload task, raise exception if "0 lines fetched"

The only way to raise an exception is to introduce an intentional syntax error like this:

IF NoOfRows('TableName')=0 THEN

    Failing due to no rows;

ENDIF

The "Failing due to no rows" is an invalid statement, but it will nicely show as the error cause as well.

-Rob