Several thousand java.lang.NullPointerException errors caused by sys_user.name Dictionary change

SebastianV
Tera Contributor

One of the previous admin/developer made a change to the sys_user.name Dictionary Record a while ago, and since then our System Log has been swamped with 7,000+ "java.lang.NullPointerException" errors by the end of every day. Here is the addition to the OOTB record:

 

if (gs.getSession().isInteractive()) { // only do for interactive sessions
    if (gs.action.getGlideURI() != "") {
      if (gs.action.getGlideURI().getMap() != '') {
        if (gs.action.getGlideURI().toString().startsWith('api/now/form/mention/record/')) { // @ mention is being used
  //         current.user_name; // return user_id field - change this combo to be anything you would like
              if(current.first_name.nil()) {
                  current.last_name +  " (" + current.email + ")";
              } else {
                  current.first_name + ' ' + current.last_name +  " (" + current.email + ")";
              }
      }
      }
    }
  }

 

I think the attempt to convert the GlideURI to a string is what's causing the error, mainly because the Mention function is used frequently by many of our ITIL users (which would explain the volume by EoD).
 
I found this solved post but would like to know if there is a more efficient way of converting our "uri" variable to a string, and if the variable itself should be renamed since 'URI' is a part of existing methods (like .getGlideURI) - here's what I have so far:

 

  if (gs.getSession().isInteractive()) { // only do for interactive sessions
    if (gs.action.getGlideURI() != "") {
      if (gs.action.getGlideURI().getMap() != '') {
        var uri = gs.action.getGlideURI().toString();
        if (uri.startsWith('api/now/form/mention/record/')) { // @ mention is being used
          //current.user_name; // return user_id field - change this combo to be anything you would like
          if(current.first_name == null) { 
            current.last_name +  " (" + current.email + ")";
          } else { 
            current.first_name + ' ' + current.last_name +  " (" + current.email + ")";
          }
        }
      }
    }
  }
  

 

Any help would be greatly appreciated!

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Can you put it in a try catch function and see how it goes? Also made few changes to the script

 

try{
  if (gs.getSession().isInteractive()) { // only do for interactive sessions
    if (gs.action.getGlideURI() != "") {
      if (gs.action.getGlideURI().getMap() != '') {
        var uri = gs.action.getGlideURI().toString();
        if (uri.indexOf('api/now/form/mention/record/')>-1) { // @ mention is being used
          //current.user_name; // return user_id field - change this combo to be anything you would like
          if(current.first_name == null || current.first_name == "") { 
            current.last_name +  " (" + current.email + ")";
          } else { 
            current.first_name + ' ' + current.last_name +  " (" + current.email + ")";
          }
        }
      }
    }
  }
}
catch(ex)
{
gs.error(ex);
}

 


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

2 REPLIES 2

SanjivMeher
Kilo Patron
Kilo Patron

Can you put it in a try catch function and see how it goes? Also made few changes to the script

 

try{
  if (gs.getSession().isInteractive()) { // only do for interactive sessions
    if (gs.action.getGlideURI() != "") {
      if (gs.action.getGlideURI().getMap() != '') {
        var uri = gs.action.getGlideURI().toString();
        if (uri.indexOf('api/now/form/mention/record/')>-1) { // @ mention is being used
          //current.user_name; // return user_id field - change this combo to be anything you would like
          if(current.first_name == null || current.first_name == "") { 
            current.last_name +  " (" + current.email + ")";
          } else { 
            current.first_name + ' ' + current.last_name +  " (" + current.email + ")";
          }
        }
      }
    }
  }
}
catch(ex)
{
gs.error(ex);
}

 


Please mark this response as correct or helpful if it assisted you with your question.

Thanks Sanjiv! I've applied the script above and have yet to see the error - happy holidays!