- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 05:31 AM
Do you have any idea on how to check, inside a workflow, if a variable exists?
Let me say, something like: if (current.variables.variableName.exists).
Because if (current.variables.variableName != '') returns an error.
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 05:38 AM
I suppose an even easier way is just to test it.
if (current.variables.var_name) {
// The variable exists and is not null
} else {
// The variable does not exist
}
The same can be done with fields as well to avoid null pointer exceptions. See the best practices.
Reference:
ServiceNow Wiki: Technical Best Practices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 05:36 AM
Hi William,
Just check using JSUtil nil() method.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 05:38 AM
I suppose an even easier way is just to test it.
if (current.variables.var_name) {
// The variable exists and is not null
} else {
// The variable does not exist
}
The same can be done with fields as well to avoid null pointer exceptions. See the best practices.
Reference:
ServiceNow Wiki: Technical Best Practices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 07:46 AM
thanks chuck!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2017 07:50 AM
You are welcome. Thanks for using the community!