Writing Null-Aware Expressions
When writing your scripts, be aware that field values can be null. You can use the nvl() null value function to easily define a value to use instead of null as part of any script expressions you use.
Consider the following examples:
// Assign a date three days after the PostedDate
// Use the current date instead of the PostedDate if the
// PostedDate is null
def targetDate = nvl(PostedDate,now()) + 3
// Increase an employee's custom Salary field value by 10 percent
// Use zero if current Salary is null
Salary = nvl(Salary,0) * 1.1
Tip: Both expressions you pass to the
nvl()
function must have the same
datatype, or you will see type-checking warnings when saving your code. For example,
if Salary
is a number field, then it is incorrect to use an
expression like nvl(Salary,’<No Salary>’)
because the first
expression is a number while the second expression is a string.