- 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 09:06 PM
Best way is you can include into your addQuery/addEncodedQuery as follows:
gr.addEncodedQuery("assigned_toISNOTEMPTY");
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 09:48 PM
Hi,
We always can't use addQuery/addEncodedQuery. Some times there would be chance to check in IF-statement
then which method would be better to follow.