Custom JavaScript button in workflow automation fails to trigger on record save in Zoho CRM 2021

I’m experiencing a frustrating issue with a custom JavaScript button I added to our workflow automation in Zoho CRM 2021. The button is supposed to trigger when a lead reaches a specific stage, but it’s throwing a ReferenceError and not executing at all.

The error message shows:


ReferenceError: $ is not defined
  at customButton.js:12
  at WorkflowEngine.execute()

I’m using jQuery for DOM manipulation and the Zoho SDK for CRM operations. The script works perfectly when I test it in the browser console, but fails completely within the workflow context. I suspect this might be related to script load order or how jQuery is being referenced in the workflow environment.

This is blocking our entire lead qualification process since the button needs to update multiple fields and trigger notifications. Has anyone encountered similar jQuery reference issues in Zoho CRM workflows?

I had exactly this problem last month. The issue is that Zoho’s workflow automation environment is isolated and doesn’t have access to jQuery by default. Instead of fighting with jQuery dependencies, I recommend using the Zoho SDK directly. It’s more reliable in workflow contexts and handles all the async operations properly.

The solution requires addressing all three aspects: removing jQuery dependency, proper Zoho SDK usage, and correct script initialization order.

First, eliminate the jQuery reference completely. The ReferenceError occurs because the workflow execution sandbox doesn’t include jQuery in its global scope. Rewrite your DOM operations using vanilla JavaScript - document.querySelector() and addEventListener() work fine in workflow contexts.

Second, structure your Zoho SDK calls properly:


ZOHO.CRM.API.updateRecord({
  Entity: "Leads",
  APIData: {id: leadId, Status: "Qualified"}
}).then(function(data){
  console.log(data);
});

Third, ensure proper initialization sequence. In your workflow configuration, add an initialization block that loads the Zoho SDK first:


ZOHO.embeddedApp.on("PageLoad", function(data) {
  // Your button logic here
  initializeCustomButton();
});

The script load order is critical - the Zoho SDK must initialize before your custom button code executes. In Setup > Automation > Workflows, edit your workflow and verify the “Custom Functions” section lists ZOHO SDK initialization at the top, followed by your custom button function.

For your specific use case (updating multiple fields and triggering notifications), use ZOHO.CRM.API.updateRecord for field updates and ZOHO.CRM.API.addNotesAndAttachNotes for notifications. Both are asynchronous, so chain them with promises or async/await.

Key points:

  • Remove all jQuery references (use vanilla JS)
  • Use ZOHO.CRM.API methods exclusively
  • Initialize SDK before custom code
  • Handle async operations with promises
  • Test in workflow sandbox, not browser console

This approach eliminates the ReferenceError and ensures reliable execution within Zoho’s workflow automation environment.

This is a common mistake when moving from client-side testing to workflow automation. The workflow engine has its own JavaScript execution sandbox that doesn’t inherit browser libraries like jQuery. You have two options: either include jQuery in your workflow script dependencies, or better yet, rewrite your code using vanilla JavaScript and the native Zoho SDK methods. The SDK provides everything you need for CRM operations without external dependencies. Also, make sure you’re using ZOHO.CRM.API methods correctly - they’re asynchronous and need proper promise handling.

I’ve seen this before. The workflow execution context in Zoho CRM 2021 doesn’t automatically include jQuery. You’re trying to use $ without it being loaded in that environment. Check if you’re loading jQuery explicitly before your custom script runs.

Thanks everyone for the insights. I’m starting to understand the isolation issue. Could someone share an example of how to properly structure a workflow button script using just the Zoho SDK? I need to update three fields and send a notification when triggered.