5 Replies · Latest reply on Jan 3, 2018 2:09 PM by Jim Freeman

    Why does GlideRecord.getValue('field_name') return null for blank columns?

      //Using Eureka version - Background Scripts

      var grContact = new GlideRecord('u_staging_ess_contacts');
      if (grContact.get('u_first_name', 'Rachel')) {
        gs.print(grContact.getValue('u_mobile_phone'));  //returns null  (initially a blank string if viewed with the form)
        gs.print(grContact.getValue('u_home_phone'));  //returns a value XXX-XXX-XXX  (a non-blank value when viewed with the form)
        grContact.setValue('u_home_phone', grContact.getValue('u_mobile_phone'));
        grContact.update();
        gs.print(grContact.getValue('u_mobile_phone'));  //returns null
        gs.print(grContact.getValue('u_home_phone'));  //returns null  (but no update was actually made to the record)
      }

      //Then run this right after.....

      var grContact = new GlideRecord('u_staging_ess_contacts');

      if (grContact.get('u_first_name', 'Rachel')) {

        gs.print(grContact.getValue('u_mobile_phone'));  //returns null

        gs.print(grContact.getValue('u_home_phone'));  //returns original value XXX-XXX-XXX, field was not updated

      }

       

      /* Questions
      u_home_phone is not updated, since it appears that setValue('u_home_phone', null) silently fails.
      Why does grContact.getValue('u_mobile_phone') return a JavaScript null and not ''?  I started relying on setValue and getValue on the GlideRecord based on listening to a TechNow Server-Side Scripting video, but am beginning to doubt the validity of their use in all cases.

       

      I switched to using grContact.u_mobile_phone.getDisplayValue(), but it would be nice to be consistent with getValue and setValue.  I don't want to have
      to test the return value for null.  I need an easy API to move values between a normal table and a staging table for export where I don't have to worry about the type.

       

      While I am at it - Why isn't the call GlideRecord.getDisplayValue('my_field_name') documented in GlideRecord.  It only documents returning the DisplayValue
      for the record and not the specified field?  Is the documentation off?

      */