- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 08:01 PM - edited 07-27-2023 08:05 PM
Hi All,
Kindly help me on below issue
which is best method to check null / not null Performance wise/ Best Script practice wise.
check assigned_to Empty/Null/:
if(gr.assigned_to==" " && gr.sys_created_by !=gr.opened_by)
if(gr.assigned_to.nil() && && gr.sys_created_by !=gr.opened_by)
if(gs.nil(gr.assigned_to) && gr.sys_created_by !=gr.opened_by)
if(JSUtil.nil(gr.assigned_to) && gr.sys_created_by !=gr.opened_by)
check assigned_to Not Empty/Not Null/:
if(gr.assigned_to!=" " && gr.sys_created_by !=gr.opened_by)
if(!gr.assigned_to.nil() && gr.sys_created_by !=gr.opened_by)
if(!gs.nil(gr.assigned_to) && gr.sys_created_by !=gr.opened_by)
if(JSUtil.notNil(gr.assigned_to) && gr.sys_created_by !=gr.opened_by)
Kindly help me on this, it has to be work for long-lasting .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 08:49 PM
Hello @Supriya25
Greetings!
- Use strict equality (===) or strict inequality (!==) where possible, as it not only compares the values but also checks the data types. As this can prevent unexpected results due to type.
- JSUtil is not available for scoped apps
- Consider readability and maintainability of the code. It's essential to write code that is easy to understand and modify in the future.
- I beleive gs.nil() and gs.notNil() are best practice in ServiceNow, as they handle null, empty strings, and undefined variables correctly.
refer below article:
Please hit the thumb and Mark as correct based on Impact!!
Kind Regards,
Ravi Chandra.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 08:49 PM
Hello @Supriya25
Greetings!
- Use strict equality (===) or strict inequality (!==) where possible, as it not only compares the values but also checks the data types. As this can prevent unexpected results due to type.
- JSUtil is not available for scoped apps
- Consider readability and maintainability of the code. It's essential to write code that is easy to understand and modify in the future.
- I beleive gs.nil() and gs.notNil() are best practice in ServiceNow, as they handle null, empty strings, and undefined variables correctly.
refer below article:
Please hit the thumb and Mark as correct based on Impact!!
Kind Regards,
Ravi Chandra.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 09:49 PM
can we use if( gr.assigned_to == " " ) if( gr.assigned_to != " " ) ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 10:55 PM
Hey Supriya!
Yes you use that.
also try gr.getValue(assigned_to) // getValue returns null when the value is empty string,but it also returns null when the value is bool "false".
Try log statements to check values you are getting.
Please hit the thumb and Mark as correct based on Impact!!
Kind Regards,
Ravi Chandra.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 06:44 AM
Hello @Supriya25
Greetings!
Any feedback on my reply? were you able to do this?
Please mark the answer as correct solution and helpful if helped.
Kind Regards,
Ravi Chandra