Try Catch Throw in ServiceNow

rcruzsnow
Kilo Contributor

So I've setup a code in a try-catch statement where it throws the code if it passes the given if-statement:

if(requestEntry.cmdb_ci == null) throw "CI is missing";

Seems correct right? But when I've executed the test on the code, a certain error came out:

"Cannot convert CI is missing to com.glide.rest.service.custom.errors.ScriptableServiceError (sys_ws_operation.a001d9284fd5ba0022493faf0310c7da.operation_script; line 110)"

Seems that the given class is not allowing me to throw the error message that I've created. Do you have any suggestions on how to work around this?

2 REPLIES 2

roehltablada
Mega Guru

Try requestEntry.cmdb_ci === null.


What I'm trying to look for is the function of the Throw statement in ServiceNow, not the operator. The suggestion you provided is simply an operator which is for a strict comparison.