Validation Rule for Controlled Stage Movement in Deals Module (Deluge Script)

Validation Rule for Controlled Stage Movement in Deals Module (Deluge Script)

For keeping a control over module stage or status, you can use the below deluge script. The below deluge script defines validation control over deals module stages:

// Function to validate allowed stage transitions in the Deals module
map validation_rule.LeadStatustValidation1(String crmAPIRequest)
{
    // Convert the incoming API request to a map and extract the 'record' map
    entityMap = crmAPIRequest.toMap().get("record");

    // Get the Deal record ID from the request (if available)
    id = ifnull(entityMap.get('id'),"");

    // Initialize the response map
    response = Map();

    if(id != "")
    {
        // Fetch the existing Deal record using the ID
        getdetails = zoho.crm.getRecordById("Deals",id);

        // Extract current and new stage values
        currentStage = getdetails.get("Stage");
        newStage = entityMap.get("Stage");

        // Log for debugging purposes
        info "Current Stage: " + currentStage;
        info "New Stage: " + newStage;

        // Define the valid stage order (used to determine forward/backward movement)
        stageOrder = list();
        stageOrder.add("Qualified Deal");
        stageOrder.add("Quotation Created");
        stageOrder.add("Negotiation");
        stageOrder.add("Quotation Accepted");
        stageOrder.add("Sales Order Created");
        stageOrder.add("Deal Won");
        stageOrder.add("Deal Lost");

        // Get the index of the current and new stage from the stage order list
        currentIndex = stageOrder.indexOf(currentStage);
        newIndex = stageOrder.indexOf(newStage);

        // Define allowed backward movement only from Negotiation to Quotation Created
        allowBackwardFromNegotiation = list();
        allowBackwardFromNegotiation.add("Quotation Created");

        if(currentIndex > -1 && newIndex > -1)
        {
            if(newStage == currentStage)
            {
                // No change in stage
                response.put("status","success");
                response.put("message","No change in stage.");
            }
            else if(currentIndex < newIndex)
            {
                // Forward movement is allowed
                response.put("status","success");
                response.put("message","Valid forward movement.");
            }
            else
            {
                // Backward movement logic
                if(currentStage == "Negotiation" && allowBackwardFromNegotiation.contains(newStage))
                {
                    response.put("status","success");
                    response.put("message","Backward movement allowed from Negotiation to Quotation Created.");
                }
                else
                {
                    response.put("status","error");
                    response.put("message","Backward movement is not allowed from " + currentStage + " to " + newStage + ".");
                }
            }
        }
        else
        {
            // Invalid stage(s) in the request
            response.put("status","error");
            response.put("message","Invalid stage(s) detected.");
        }
    }
    else
    {
        // No ID provided in the request
        response.put("status","error");
        response.put("message","Record ID is missing.");
    }

    // Return the final response
    return response;
}


Note: You can apply the same concept for leads module also. Thanks.
    • Recent Topics

    • Preferred Name and Email Formats: Bring consistency to user identity

      A user's display name and email address are often the first identifiers that colleagues, partners, and customers see. Maintaining a consistent format across the organization helps reinforce a professional identity and avoids the confusion that comes from
    • [Webinar] Solving business challenges: Standardizing document operations across your organization

      Hi Writer users, Every organization struggles with document inconsistency due to issues like multiple templates, outdated content in client-facing docs, and the lack of a standard review process. Zoho Writer streamlines the entire lifecycle with capabilities
    • Auto-sync field of lookup value

      This feature has been requested many times in the discussion Field of Lookup Announcement and this post aims to track it separately. At the moment the value of a 'field of lookup' is a snapshot but once the parent lookup field is updated the values diverge.
    • Account name not populating when importing contacts

      When importing a csv file to add contacts the account name is blank? Every other filed gets mapped and imported correctly, i.e contact name, phone number. However not the account name which I have mapped to "company" field in my csv file
    • Requirements using Zoho Projects

      Is there a seperate Zoho application for Requirements (Requirements Repository) or a way to use Zoho Projects to store, track and organize software requirements
    • Control who sees Timeline and Interactions in Zoho CRM through Profiles

      The feature has been enabled for all DCs (except US, EU, and IN DCs). We will be rolling it out to the other DCs in the upcoming days. Dear All, In a CRM, not all users would require access to the history of a record. For instance, a Marketing Operations
    • Billing Management: #3 Billing Unbilled Charges Periodically

      We had a smooth sail into Prorated Billing, a practice that ensures fairness when customers join, upgrade, or downgrade a service at any point during the billing cycle. But what happens when a customer requests additional limits or features during the
    • Hide chart series by default (unchecked in legend)

      Hi, I’m working on a dashboard in Zoho Analytics and ran into a limitation I can’t figure out. Is there a way to have certain columns (series) in a chart hidden by default via the legend (i.e., unchecked), but still available so the user can enable them
    • Zoho CRM - Restrict Login based on work hours

      Hi there, I'm wondering if we can restrict users to login during works - For example the users would be able to login from 8am to 5pm. I have seen the IP address restriction - the only downfall is what if the customer has dynamic IP. thanks Jiri
    • ZDK.Client.showConfirmation() and showAlert() silently fail on Boolean/checkbox field onChange - anyone else?

      Hi community, I've been trying to show a message pop-up when a checkbox field is ticked. I'm using the onChange event on the Opporutnities create page. function onChange(value) { if (value === true) { ZDK.Client.showMessage( "Note: Message goes here.",
    • Tip #22 Three ways you can split your text into columns

      When you're working with large datasets, you often have the problem of messy, inconsistent formatting, which makes analysis difficult. This is especially true when the data is being collected elsewhere and then imported to the spreadsheet, which can result
    • CRM Timeline History Permissions ?

      Hello, I am curious about this. in Zoho CRM on the Timeline Tab everyone knows that it displays the history of edits and such for that particular Lead record. What if I wanted to Hide some of the History Events from CRM Users? For example, I have a workflow
    • Zia Emails Summary: Instant context from past emails

      Hello all, Reading all of the past emails associated with a specific record can be tedious, which in turn makes it difficult to understand the context quickly, as these messages often include irrelevant details that waste time. This is true for everyone
    • Custom Display Field for Lookup Dropdowns in Zoho CRM

      Could Zoho CRM support changing the display field in lookup dropdowns, like Zoho Creator does? This would make it much easier to select the right record by showing a more useful field instead of only the default one. It would improve speed, clarity, and
    • Can receive but not send messages in Zoho Mail

      Hello! I was able to configure my email client successfully in that I can receive messages just fine. However, when I send messages out, they seem to go out fine (I don't receive any errors or anything), but the recipient does NOT receive those messages.
    • Email is not being delivered.

      I was always able to send my emails normally but in the last two weeks I noticed that my emails are not being received by one company. Before this two weeks everything was ok we were sending messages and emails without a problem, but then they stopped receiving my email. I tried adding other email addresses to see if other users can get the mail and indeed they do but the most important company is not receiving it.  We already asked to see the Spam and Not wanted email, but it was not there either.
    • Emails are not sent to Hotmail emails.

      Hi, We are getting this message when we send email to any of Microsoft email service. This message was created automatically by mail delivery software.  A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. qasims@live.se, ERROR_CODE :550, ERROR_CODE :5.7.1 Unfortunately, messages from [31.186.226.248] weren't sent. Please contact your Internet service provider since part of their network is on our block list (S3150). You can also refer your provider
    • Hotmail is blocking the zoho mail IP

      Greetings, Since last Tuesday (5 days ago today) I wrote to Zoho support and I still haven't received a single response (Ticket ID: 2056917). Is this how you treat people who pay for your email service? I am making this public so that those who want to
    • Zoho Desk View Open Tickets and Open Shared Tickets

      Hi, I would like to create a custom view so that an agent can view all the open tickets he has access to, including the shared tickets created by a different department. Currently my team has to swich between two views (Open Tickets and Shared Open Tickets).
    • Survey isn't Sending

      I have published my survey and uploaded my distribution list, which is within the limits of the plan I have. I cannot get it to send, despite repeated attempts. I'm beyond frustrated. Has anyone encountered this problem and how did you fix it?
    • Contacts are imported successfully but ignored when I send a campaign (due to non-marketing type)

      Can someone please help, When we sent a campaign yesterday, we received the following message: "The number of contacts from the selected mailing lists are 161. We have ignored 11 contacts due to its non-marketing type." So only 150 people got the message.
    • Problem: New Email Consistently Failing to Sync/Display in Inbox

      Recently, I have noticed that my Zoho Email inbox does not indicate I've received a new email, until I go to *another* folder and then return to the inbox. Only then will new emails be displayed. This has happened 100% of the time, during the past few
    • Campaing on hold for more than a week

      As someone with an existing site, I use Brevo to send newsletters to my users. Decided to tryout Zoho only for my first campaign to be placed on hold. Tried reaching out to support, but no response. Zoho Campaigns claims that my domain is new and the
    • Stop by and explore our six updates in ABM for Zoho CRM

      Dear Customers, We hope you're well! ABM for Zoho CRM is built to sharpen your database so that you engage with the right set of customer accounts. To fine-tune it further, we have six new updates: New access location for ABM Refined account entry criteria
    • CRM gets location smart with the all new Map View: visualize records, locate records within any radius, and more

      Hello all, We've introduced a new way to work with location data in Zoho CRM: the Map View. Instead of scrolling through endless lists, your records now appear as pins on a map. Built on top of the all-new address field and powered by Mappls (MapMyIndia),
    • Possible to connect Zoho CRM's Sandbox with Zoho Creator's Sandbox?

      We are making some big changes on our CRM so we are testing it out in CRM's Sandbox. We also have a Zoho Creator app that we need to test. Is it possible to connect Zoho CRM's Sandbox to Zoho Creator's Sandbox so that I can perform those tests?
    • Zoho CRM Community Digest - March 2026 | Part 2

      Hello Everyone! The second half of March 2026 arrived with a wave of announcements, from AI becoming more intuitive to security authorization protocols getting tighter, and a few community threads that quietly solved problems a lot of you have likely
    • Cross-Project Resource Capacity Planning View for All Users

      Zoho Projects has a workload and resource utilization view, but it is scoped per project. There is no native way for a manager to see a single view of how a team member is allocated across ALL active projects simultaneously. This means that when assigning
    • SMTP and API

      I cannot acess my account as its says "Access Denied". I have contacted on support@zeptomail.com. But no response.
    • Free Webinar Alert! Zoho Mail: An admin’s guide to email security reports and monitoring

      Hello Zoho Community! Are you struggling to keep track of your organization’s email activity? Wondering how to stay ahead of potential security threats? We’ve got a session you won’t want to miss. In our Zoho Mail: An admin’s guide to email security reports
    • Pinned important comments and threads in tickets

      Hello everyone, We are happy to announce that users can now pin important comments and threads in a ticket. This feature helps agents quickly access the customer's requirements and stay updated on the latest developments to ensure they have up-to-date
    • How we reduced manual ops using Zoho One (real use case)

      Hey community 👋 Sharing a quick use case - A growing business had disconnected systems across CRM, inventory, and storefront, leading to manual data entry, no real-time stock visibility, and limited reporting. What we did: Centralized data with Zoho
    • Introducing SlyteUI : From Idea to a Working Interface in Minutes

      SlyteUI is now live across all DCs as of 4th May 2026! Hello everyone! Are you spending hours building basic UIs? Does even the smallest customization feel like a major task? CRM customization should feel intuitive and straightforward, not time consuming
    • How to install Widget in inventory module

      Hi, I am trying to install a app into Sales Order Module related list, however there is no button allow me to do that. May I ask how to install widget to inventory module related list?
    • Inbuilt Telephony

      How do I replace InBuilt telephony with a custom PhoneBridge widget that's privately published in the Developer Console? I want to gain the usage of the telephone icon on the leads module in ZOHO CRM.
    • Zia flags the deal as at risk - but leaves my customers figuring out the rest themselves

      I implement Zoho for many businesses. Team sizes vary, some clients have 3 reps, some have 40. But I keep hearing the same complaint across all of them and I figured it's worth raising here. Zia's deal scoring has genuinely improved over the past year.
    • Calculate Hours Minutes Sec in Zoho Creator Using Deluge

      check_In = "8-Aug-2023 10:00:00".toDateTime().toLong(); checkout = "8-Aug-2023 18:00:00".toDateTime().toLong(); //difference = start.timeBetween(end); check_In = "8-Aug-2023 17:56:50".toDateTime().toLong(); checkout = "8-Aug-2023 18:00:00".toDateTime().toLong();
    • Customizing Global Search Settings for All Users

      Hi Our team use the brilliant global search functionality within CRM many many times daily. But, we struggle with the out-of-the box columns that CRM gives you. We are always telling users to customize this look to more suit our business, to show the
    • favorites no longer listed

      Hello, I can no longer navigate to my Favorites from the pulldown at the top of my grid view (see attached screenshot). I wasn't able to find it anywhere! Please help me display my Favorites. Thank you!
    • Super Admin Logging in as another User

      How can a Super Admin login as another user. For example, I have a sales rep that is having issues with their Accounts and I want to view their Zoho Account with out having to do a GTM and sharing screens. Latest Update (27th April 2026): With the early
    • Next Page