1173 views

Description

When a record field is updated with NULL value instead of (empty string), a before business rule that evaluates if the value is empty by calling the .nil() method will return false. The expected result is true because an empty value is written to the database.

Steps to Reproduce

Create a Before business rule that evaluates if one of the record fields is empty or null by using the '.nil()' method.

  1. Insert a new Before business rule that runs on Insert and Update with the script below:

    gs.log('Business rule is analyzing ' + current.sys_id + ', current.user_name=' + current.user_name, 'PRB637696');
    if (current.user_name.nil()) {
        gs.log(current.sys_id + ' user_name seems to be NULL or empty, current.user_name=' + current.user_name, 'PRB637696');
    } else {
        gs.log(current.sys_id + ' already has current.user_name=' + current.user_name, 'PRB637696');
    }

  2. Use the script below to update a sample user record (abel.tuter) with 'NULL' value:

    var gr = new GlideRecord('sys_user');
    gr.addQuery('sys_id','=','62826bf03710200044e0bfc8bcbe5df1');
    gr.query();
    while(gr.next()) {
      gs.log(gr.sys_id + ' has current user_name=' + gr.user_name, 'PRB637696');
      gr.user_name = 'NULL';
      gr.update();
      gs.log(gr.sys_id + ' has been updated with user_name=' + gr.user_name, 'PRB637696');
    }

  3. Use the script below to update the same record again but this time with a non-empty string:

    var gr = new GlideRecord('sys_user');
    gr.addQuery('sys_id','=','62826bf03710200044e0bfc8bcbe5df1');
    gr.query();
    while(gr.next()) {
      gs.log(gr.sys_id + ' has current user_name=' + gr.user_name, 'PRB637696');
      gr.user_name = 'abel.tuter';
      gr.update();
      gs.log(gr.sys_id + ' has been updated with user_name=' + gr.user_name, 'PRB637696');
    }

Workaround

Extend the business rule condition with OR operator and compare the value with 'NULL'.

For example:

(current.name.nil() || current.name == 'NULL')

Note: Subscribe to this known error article (click Subscribe button at the top of the article) to receive notifications when more information is available about this issue.


Related Problem: PRB637696

Seen In

Calgary Patch 7 Hot Fix 2
Fuji Patch 8

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2016-01-15 13:34:41
Published:2015-07-20