Null check parameters

Discussions about the LSPS expression language.
Forum rules
Make sure every topic contains information about your LSPS version and if relevant also your server OS, client OS, database name and version, and application server name and version.
eric.graham
 
Posts: 58
Joined: Tue May 13, 2014 12:20 pm

Null check parameters

Tue Mar 31, 2015 10:07 pm

Is there a way (i.e. build in method, or some other way) to null check parameter in the expression language? As in:

For Each Loop in Task - Multi-Instance - Sequential Ordering - Calling a customer Java class/method
Iterator: myDataType

def MyDataType mdt;
mdt := callSomeMethod(ticket, someOtherData);
mtd.myDataType

Is there a way here to check if ticket and/or someOtherData is null inside the loop? (or at least safe check for null in case they are null)?

Thanks

neil.lee
 
Posts: 14
Joined: Wed Jul 23, 2014 4:38 pm

Re: Null check parameters

Tue Mar 31, 2015 10:35 pm

Eric,

If you have access to the parameters in the expression block, then you can perform a conditional check as well as any additional processing you need to perform before calling the method:

if(ticket = null) then _do_something_ end;
def MyDataType mdt;
mdt := callSomeMethod(ticket, someOtherData);
mtd.myDataType

You could also do the conditional check inline with the ?? operator (which is shorthand for "if null then"): mdt := callSomeMethod (ticket ?? yourAlternativeToNullHere, someOtherData);

On a tangential note, you can use the null safe operator (?.) to avoid an exception when attempting to access a field that could be null: mtd?.myDataType will return null if myDataType is null and the value of myDataType if it isn't.

Return to Expression language

Who is online

Users browsing this forum: No registered users and 1 guest