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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
isaiah82
Creator III
Creator III

Force script error

Is it possible to conditionally force script execution to end -AND- be treated as an error?

For example, if a query or stored procedure doesn't return any results I would like to end the script execution as an error.  I know I can use EXIT SCRIPT but this is treated as a graeful script completion and therefore can't be used to send a failure notification from Publisher et al. unless I am missing something.

Anybody doing anything like this today or have ideas?

Thanks -Isaiah

10 Replies
jvitantonio
Specialist III
Specialist III

Hi,

You can use ErrorMode and ScriptError in your script. Look for "ErroMode" in the help.

isaiah82
Creator III
Creator III
Author

Thanks qlikuser14 but that's not exactly what I need.  I want to be able to be able to set the value of ScriptError myself based on some logic; e.g. a query doesn't return any results (simply because there aren't any records returned; not because of an OLEDB/ODBC error.)  I tried using a SET statement to set the value but that doesn't work.  Any other ideas?

Thanks -Isaiah

erichshiino
Partner - Master
Partner - Master

Hi, Isaiah.

It is not an elegant solution, but you could force an error with a wrong statement:

Table:

SQL Exec yourProcedure ....  .... ;

if alt( NoOfRows('Table'), 0)  < 1  then //I used alt() because NoOfRows was not enough...

          asdfkjsdflkks; //or any wrong command

 

end if

Hope if helps,

Erich

isaiah82
Creator III
Creator III
Author

Erich > I love it!  I'm all about non-elegant solutions when they're the only option and they function well.

Thanks -Isaiah

jonathandienst
Partner - Champion III
Partner - Champion III

Isaiah

I posted an idea a while ago on the Ideas side of the site to allow the script to be conditionally terminated. Please vote for the idea if you think it would help.

http://community.qlik.com/ideas/1956

Regards

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
isaiah82
Creator III
Creator III
Author

Thanks for sharing Jonathan > I don't know why I didn't come across this in my initial query.  I voted up on the idea; this would be great functionality.  -Isaiah

bumin
Partner - Creator II
Partner - Creator II

I have used

let vNoDoclines = NoOfRows('oas_docheadlinesMod');

if IsNull(vNoDoclines) then

    trace  ---   no docline records   ---;

    Exit script;

ENDIF;

works also

erichshiino
Partner - Master
Partner - Master

Yes, this can also be used.

The difference is that 'Exit script' will not return an error. You would have a successful task on the server.

That other case would have a failed task.

Thanks!

Erich

jonathandienst
Partner - Champion III
Partner - Champion III

Plus the qvw file will be saved with an empty table for the tested table and anything built after the conditional check. If the reload "fails", it should not save the failed file.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein