We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

check undefined

deepika46
Tera Contributor

Hello experts,

 

Is there any way we can check undefined in servicenow using a gs function?

 

I am new to SNOW Scripting.

4 REPLIES 4

Harsh_Deep
Giga Sage

Hello @deepika46 

You can use current.field_name==undefined   OR

if(gr2.variables.server_name != undefined){

 

If this will not resolve your query then

Can you please explain your query ?

hi harsh,

 

i am using "var rc = cart.placeOrder();". In some cases rc , it is not creating a request i.e not genrating a sys id of the request and generating undefined or null . Is there any way i can check that? So only if it returns a sys id then only it should go and execute further lines of code, else it should stop if rc returns undefined or null or even empty

Hello @deepika46 

 

You can use 

  1. if(rc==undefined || rc==null)

Please accept the solution and mark as helpful, if it helps you.

Tai Vu
Kilo Patron

Hi @deepika46 

Let's try this.

 

//nil(o: Object): boolean
gs.nil(<variable>); //Queries an object and returns true if the object is null, undefined, or contains an empty string

 

 

Also this one

 

JSUtil.nil(<variable>);

 

 

 

Let me know if it works for you.

 

Cheers,

Tai Vu