
Deluge Tips – Null Check
When scripting, ask yourself this question – will this value ever be null? If it’s a yes, that’s a place for a null check! Here are 3 tips and best practices to help you kickstart the habit.
Safeguarding your script with sufficient null checks is a discipline that every Zoho developer should cultivate. Imagine the frustration when troubleshooting a long and complex script only to find out that the errors were caused certain null values. Why go through the headache of fixing it when you can avoid it? When scripting, make it a habit to ask yourself this question – will this value ever be null? If it’s a yes, that’s a place for a null check! Here are 3 tips and best practices to help you kickstart the habit.
It’s often easy to write record.get(“Lookup_Field”).get(“id”) when you’re trying to get the ID of a lookup field on a record. But if the lookup field on the record is null, your script will fail at .get(“id”). Here’s a simple method of avoiding that:
lookupID = ifNull(record.get("Lookup_Field"),{"id":"none"}).get("id");
if (lookupID != "none")
{
//Write your subsequent actions here
}
Other Usage:
The ifNull() function is also useful when you are getting certain fields values to be populated somewhere else.
When performing a zoho.crm.searchRecords function, we need to take into account that sometimes there will not be a match in the search. Without a null check in place, your subsequent actions that depend on the search record will fail. The search record Deluge task returns a list variable. The size() and isEmpty() can be used to validate against a list.
email = "hello@theworkflowacademy.com";
contact = zoho.crm.searchRecords("Contacts", "Email:equals:"+email);
if (contact.size() > 0)
{
//Write your subsequent actions here
}
When you get() a string field from Zoho CRM and there’s no value in that field, it will return null. Whereas in Zoho Creator, it returns an empty string “”. Zoho Invoice/Books has a rather peculiar way of dealing with null values for custom fields – when there is no value in a custom field, the field name simply does not show up in the custom field map in the record. When it comes to writing null checks, it is important to know how Zoho returns null values for different apps.
Zoho CRM: Validate with null.
if (field != null)
{
//Write your subsequent actions here
}
Zoho Creator: Validate with empty string “”.
if (field != "")
{
//Write your subsequent actions here
}
Zoho Invoice/Books: Validate with containKey().
if (record.get("custom_field_hash").containKey("Custom_Field"))
{
//Write your subsequent actions here
}
Note: All Zoho Invoice/Books custom fields will be stored in a “custom_field_hash” map in the record info.
Click here to copy these scripts. For more Zoho-wizardry, check out our GitHub page.
When scripting, ask yourself this question – will this value ever be null? If it’s a yes, that’s a place for a null check! Here are 3 tips and best practices to help you kickstart the habit.
Learn to create a customized inventory report with Zoho Analytics. This tutorial contains a link to our GitHub page for SQL code that will help with your table creations.
How nice would it be if you could, at the press of a button, send clients an email w/a Zoho Books invoice? Replete with “Pay Now” buttons that link to PayPal/Stripe/other payment gateways?
Whether you work primarily out of CRM or the Zoho Finance Suite, you can use Analytics to build commissions dashboards. This involves some fairly simple SQL code.
If you are an inventory manager, this blog post could change your life. If you are not, it will at least teach you how to build some wicked inventory tracking for your business.
Convert fields, related activities, attachments, notes and more from one record to another across modules via custom function.