Calculated Fields - Beware they are lying to you

Christopher17
Tera Guru

Impacted releases: (San Diego and Tokyo confirmed)

Problem: [1]Queries do not return proper data on calculated fields.

 

Attached is a simple update set that creates the 'u_impossible' table. It creates a simple table with three columns:

  • u_active - True/False that you manually set
  • u_not_active - True/False that is calculated to be the opposite of u_active
  • u_label - String to identify rows for testing.

Use the update set or create your own, it's very simple to replicate.

 

Along with this table you will want the following script you can run either as a background script or fix script. The choice is yours.

var br = new GlideRecord('u_impossible');
//br.addQuery('u_not_active',0);
br.query();
br.next();
gs.info(br.getValue('u_label') + ': Active = ' + br.getValue('u_active') + ' Not Active = ' + br.getValue('u_active'));

Steps:

  1. Create a row in u_impossible table where where u_active = true, give it some u_label, and then leave u_not_active alone (by default it's checked because the initial value of u_active is false). You will see in the list view that u_active is true and u_not_active is false. This is expected.
  2. Run the script provided above. You will see that u_active is true and u_not_Active as true; expect that u_not_active would return false.
  3. Go back to the u_impossible table and change the row's u_active to false, save, and refresh. You will see in the list view that u_active is false and u_not_active is true. This is expected.
  4. Run the script provided above. You will see that u_active is false and u_not_Active as false; expect that u_not_active would return true.
1 REPLY 1

Mike_R
Kilo Patron
Kilo Patron

I try to stay away from calculated and function fields. Too many issues and unpredictable behavior.