Page 1 of 1

Null check parameters

Posted: Tue Mar 31, 2015 10:07 pm
by eric.graham
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

Re: Null check parameters

Posted: Tue Mar 31, 2015 10:35 pm
by neil.lee
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.