check undefined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 11:20 AM
Hello experts,
Is there any way we can check undefined in servicenow using a gs function?
I am new to SNOW Scripting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 11:21 AM - edited 10-24-2023 11:27 AM
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 11:28 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 11:32 AM - edited 10-24-2023 11:33 AM
Hello @deepika46
You can use
- if(rc==undefined || rc==null)
Please accept the solution and mark as helpful, if it helps you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 08:47 PM
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