igaray
ServiceNow Employee
ServiceNow Employee

Our platform makes difficult tasks easy. This simplification ServiceNow provides their customers effects how the customer developer thinks. They forget that programming is really not an easy task, and begin scripting without restraint. Developers must be strict on themselves: always testing, always checking, especially working in any platform that they did not create. Developers must ensure their customization coincides with the ServiceNow platform as one.

How an engineer customizes a ServiceNow instance relates to how many issues their company will have during business hours. Good customizations do not disrupt, bad customizations cause nightmares.

If you are going to customize ServiceNow do it right! Many customization issues are a simple fix on the engineer's side: check the variables.

Checking your variables while developing

If you're not sure why your program is broken, then you may want to start with checking your variables.   Overall, variable checks establish a safe place for you to start your customization safely.

Checking your data will ensure that you are more than 50% done.

Checking your code allows you to:

  • See concrete data
  • Alert yourself when something is wrong
  • Ensure that it is not your mistake
  • Move on the the real issues in your system that deserve time, like the logical aspects of it.

Before assuming things just work, you owe it to yourself, to ensure you are working with good data.   For example, a manager opens an incident, frustrated with ServiceNow because their their engineer claims the one week issue they are experiencing is a ServiceNow error.   The business suffers and loses valuable work time, the manager says this is something ServiceNow must fix.   A ServiceNow support engineer reviews the incident and in a few hours can find the issue. In this case, it is clearly a modification on the client side.

The customization error, "variable is undefined," means the engineer's variables were non-existent or not defined well and caused the system to stop rendering correctly. An error like this can delay a roll out of a product for one month. This could have been resolved early on if the developer took a moment to review their variables.

How To Check Variables Basics in Javascript

The basic variable culprits that could be messing with your customization:

  • Undefined
  • Null
  • "" (empty string)

You need to check for these elements, to ensure that they do not prevent your instance from working correctly.

For any variable element where "elem" is the variable.

if (elem === null)   //try this

//OR

if (typeof elem === "undefined") //try this

//OR

if(elem === "")   //try this

You should be running the above three checks on every variable in your software, scripts, and applications. You can put the above example in a function so you don't have to rewrite them.   Once in a function you can return anonymous functions to correctly handle the variable's error in a safe manner rather then breaking your interaction.

For example:

function isEmpty(elem){

      if (elem === null) {

              return function(){ alert("Is Null");};

      }

      else if (typeof elem === "undefined"){

              return function(){alert("IS UNDEFINED");}

      }

      else if(elem === ""){

              return function(){alert("IS EMPTY STRING");}

      }

      alert("NOT EMPTY");      

}

//This would be more helpful if your anonymous functions found alterior methods to notify the user of the issue or just found an entirely different work

//around to the error

You can easily test this out in the developer console in Chrome, IE, or FireFox. You will see an error described by a red X.

For example:

developer console.jpg

Unchecked variables cause all sorts of funny stuff to happen.   Unchecked variables are usually hard to find and cause the working of a page to halt.   Many Customers assume variables are just there and work correctly all of the time. The assumption that something should just exist without question, is dangerous and can affect your company's bottom line.

You own your instance and your source code, so you know what goes on inside of it.

Want to save yourself some time and possible headache? Double check the data you are working with.

4 Comments