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.

      Zoho Campaigns Resources


        • Desk Community Learning Series


        • Digest


        • Functions


        • Meetups


        • Kbase


        • Resources


        • Glossary


        • Desk Marketplace


        • MVP Corner


        • Word of the Day


        • Ask the Experts


          Zoho CRM Plus Resources

            Zoho Books Resources


              Zoho Subscriptions Resources

                Zoho Projects Resources


                  Zoho Sprints Resources


                    Zoho Orchestly Resources


                      Zoho Creator Resources


                        Zoho WorkDrive Resources



                          Zoho CRM Resources

                          • CRM Community Learning Series

                            CRM Community Learning Series


                          • Tips

                            Tips

                          • Functions

                            Functions

                          • Meetups

                            Meetups

                          • Kbase

                            Kbase

                          • Resources

                            Resources

                          • Digest

                            Digest

                          • CRM Marketplace

                            CRM Marketplace

                          • MVP Corner

                            MVP Corner




                            Zoho Writer Writer

                            Get Started. Write Away!

                            Writer is a powerful online word processor, designed for collaborative work.

                              Zoho CRM コンテンツ



                                ご検討中の方

                                  • Recent Topics

                                  • Associate project with timer on iPhone

                                    When I start the timer without first associating a project (on my iPhone), its starts fine but now when I need to associate a project, and click on the link, I get a list of EVERY project I've ever put into Zoho Books. It used to just show active projects.
                                  • Announcing the new SKILL.md for Zoho CRM and the updated OAS repository!

                                    We are introducing a new zoho-crm skill to make working with Zoho CRM Developer tools (like APIs, functions, widgets, client scripts, queries etc) easier and faster, with the help of AI in your preferred AI harness like Claude Code, Codex, Cursor, VSCode
                                  • Zoho Campaigns EU Topics API returns HTTP 200 with empty topicDetails

                                    Hello, Our Zoho Campaigns EU organisation has two custom topics visible in the Campaigns UI, and contacts are subscribed to them. However, an OAuth request with ZohoCampaigns.contact.READ to https://campaigns.zoho.eu/api/v1.1/topics returns HTTP 200 with
                                  • Caso de Éxito: Cómo Toyota Financial Services unificó la atención al cliente con Zoho

                                    "Después de seis meses con el CRM en producción estamos encantados." Miriam Cárdenas, Responsable Departamento ATC Toyota Financial Services es la división financiera de Toyota encargada de gestionar la financiación de vehículos y, junto con KINTO España,
                                  • Zoho Books - France

                                    L’équipe de Zoho France reçoit régulièrement des questions sur la conformité de ses applications de finances (Zoho Books/ Zoho Invoice) pour le marché français. Voici quelques points pour clarifier la question : Zoho Books est un logiciel de comptabilité
                                  • Automatically remove commas

                                    Team, Please be consistent in Zoho Books. In Payments, you have commas here: But when we copy and paste the amount in the Payments Made field, it does not accept it because the default setting is no commas. Please have Zoho Books remove commas autom
                                  • Zoho ERP | Product updates | July 2026

                                    Hello users, We're back with another round of updates to help you streamline your operations. This month's release brings new features and enhancements designed to help you work more efficiently. Read on to discover everything that's new in Zoho ERP this
                                  • Zoho CRM

                                    Cuándo voy a adjuntar un archivo .pdf en un registro en el campo Archivo obtengo el siguiente error:
                                  • Can I hide some products from a particular customer

                                    HI I want ot give a customer access to the portal but I need to hide some products from them that are not available for them to buy- is this possible ?
                                  • Dashboard/Component filter by probability

                                    Hi all Can I request the ability to add a Component or Dashboard filter for Deal Probability? Would be useful to be able to see data of deals more than 60% probable. Olly
                                  • 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
                                  • OpenAI Is Moving to the Responses API: Here's What It Means for SalesIQ

                                    OpenAI has deprecated its Assistants API and is moving to the Responses API. If you're using OpenAI Assistants with SalesIQ, you may be wondering if you need to make any changes to your existing setup. You don't. SalesIQ has already taken care of the
                                  • Free webinar: Zoho Sign for Microsoft apps

                                    Hello, Did you know Zoho Sign works right inside the Microsoft apps you already use? A signature request shouldn't mean leaving Teams for another tab, or downloading an Outlook attachment just to sign it. Zoho Sign integrates with Microsoft 365, Teams,
                                  • Billing Status and WO Status Field Colors -

                                    Hello Team, I noticed that the colors of the Billing Status and WO Status fields in the WO module have been changed. (Org ID:170000078905) This is not urgent to correct, but I wanted to bring it to your attention so you can check whether this is a system
                                  • Introducing throw statements in Deluge

                                    Hello everyone, We're introducing a powerful addition to Deluge that gives you more precise control over error handling in your scripts. Whether you're calling an external API, validating user input, or enforcing a business rule, there are moments when
                                  • Zoho Notebook、実はこんなところから使えます

                                    ユーザーの皆様、こんにちは。ゾーホージャパンの田村です。 前回に続き、今回もZoho Notebookをご紹介します。 関連情報 メモの保存場所、見直しませんか?― Zoho Notebookで始める情報管理 仕事中、「この内容、メモに残してあとで見返したいな」と思う瞬間はありませんか? 会議中の一言、お客様とのやり取り、CRMで見つけた気づき、 ほんの数秒で終わる内容だからこそ、「あとで書こう」と思って、そのまま忘れてしまうこともあります。 そこで今回は、PCやスマートフォンはもちろん、普段お使いのZoho製品からもすぐにアクセスできるノートアプリ「Zoho
                                  • I have been looking for CVID to get segmate list where & how can fnd it?

                                    I am trying to get segment details from the Zoho API. The API documentation says that the CVID is a mandatory parameter, but I cannot find the CVID in the "getmailinglists" API. Can you tell me where to find the CVID?
                                  • How do I increase the email attachment size in Zoho CRM ?

                                    It looks like I'm limited to 10MB when sending an attachment using the email widget on a record in Zoho CRM. Is there a way to increase the size? Or can I use some other tool? From what I'm reading online, I'm maxed out at 10MB. Any insight would be greatly
                                  • Introducing Incentives for Zoho CRM: Build, automate, and track sales commissions

                                    Dear Customers, We are here with an amazing news! We built a direct solution to help manage your commission provisioning activity in your business. From creating commission plans to issuing payouts, this application leverages your sales reps’ performance
                                  • Subforms and automation

                                    If a user updates a field how do we create an automation etc. We have a field for returned parts and i want to get an email when that field is ticked. How please as Zoho tells me no automation on subforms. The Reason- Why having waited for ever for FSM
                                  • Cannot format "start date" field in Zoho Flow

                                    I am trying to recreate a flow that connects Inventory package creation to Zoho projects (where a task is created in a defined project). I've been able to troubleshoot everything EXCEPT the date fields; specifically the "start date" - which is quite important
                                  • Dynamic Signature - Record owner

                                    Hi everyone, I’m using Zoho Writer merge templates from Zoho CRM and have two questions: Owner signature: How can I automatically insert the CRM record owner’s signature in the merged document? I’m not sure where this signature is stored or how to reference
                                  • Add ZeptoMail to Zoho One

                                    Hi Zoho Team, I would like to request that ZeptoMail be added as a fully included application within Zoho One. Why this is important Zoho One is positioned as a unified business operating system that brings the applications an organization needs under
                                  • GETTING THERE THANKS

                                    So we are still testing thanks to the great Zoho team for firstly getting pricelists working (essential) and writing some code to hide delivery and pickup options. Brilliant. So price lists are a definite mainly because of VAT. We run our Zoho books with
                                  • Time Zone is incorrect

                                    Time zone is not working properly...I've checked it twice. I'm eastern U.S. time it's currently 12:22 pm EST. CRM shows 3:22 pm EST.
                                  • CRM wants to access other apps and services on this device (Documents area)

                                    Did anyone else see this today? It only seemed to popup in the Documents area. Blocking it did not stop the ability to upload files there... Why is this coming up and what apps/services is it requesting in the background? Also, is it applicable elsewhere
                                  • Custom module - change from autonumber to name

                                    I fear I know the answer to this already, but thought I'd ask the question. I created a custom module and instead of having a name as being the primary field, I changed it to an auto-number. I didn't realise that all searches would only show this reference.
                                  • How can I populate dropdown data with information from another source or app?

                                    I want to maintain a list of items in another app (say in excel or another database) and sync those as items in a drop down menu, instead of copy pasting to import. Is this kind of a feature available?
                                  • Dynamic Field Folders in OneDrive

                                    Hi, With the 2 options today we have either a Dynamic Parent Folder and lots of attachments all in that one folder with only the ability to set the file name (Which is also not incremented so if I upload 5 photos to one field they are all named the same
                                  • Zoho Tables is now available in Zoho One!

                                    Hello Zoho One users, We’re excited to announce that Zoho Tables is now included as a part of Zoho One suite! As teams grow, managing projects, approvals, inventories, campaign trackers, and operational workflows across multiple spreadsheets become difficult.
                                  • Getting there -thanks

                                    So we are still testing thanks to the great Zoho team for firstly getting pricelists working (essential) and writing some code to hide delivery and pickup options. Brilliant. So price lists are a definite mainly because of VAT. We run our Zoho books with
                                  • I want to prefill CRM Account information using the GSTIN of the Customer

                                    Currently i need to add account details manually in zoho crm and when it syncs in zoho books manual working needs to be done. Whereas in zoho books i can prefill the customer details using the GSTIN which is great feature. Can the same be enabled for
                                  • #3 Making it look like my business

                                    Day 3: Meera had created her first invoice. The numbers were right, but something still felt unfinished. Her studio name was there, but the address did not look the way she wanted. Her logo was missing, and the invoice did not really feel like it came
                                  • Using IMAP configuration for shared email inboxes

                                    Our customer service team utilizes shared email boxes to allow multiple people to view and handle incoming customer requests. For example, the customer sends an email to info@xxxx.com and multiple people can view it and handle the request. How can I configure
                                  • Scan & Fill with double quote key/value pairs

                                    Hi, An old Ticket moved to a Topic/Idea: I love the idea of the new Scan & Fill as it nearly covers my previous request for a QR Scanner to read a multi-part QR Code. My QR Codes are hard-coded as below: {"key1":"value1","key2":"value2","key3":"value3"}
                                  • Increase the "Maximum Saved Entries per User" Options Limit

                                    Hi, You can create lots of saved entries, yet the Limit when you apply one is 25, we may often expect 32 to be in draft, and therefore want to enforce that, can we increase the limit of this field from 25 to 100 (As you can just turn it off and have more
                                  • HEIC File Type Viewer

                                    Hi, It would be nice to be able to click on the images in the All Entries/Reports Tables which are HEIC the same as JPG, PNG, etc. so they open in a viewer from Zoho or the Attachment Service, today HEIC requires you to download each image and open it
                                  • Map Dependency Upgrades in Zoho CRM

                                    Map Dependency Fields enhancements are now available across all DCs. Hello everyone, We’ve introduced a set of enhancements to Map Dependency Fields to make setup simpler, faster, and more intuitive. Map Dependency helps control how values appear across
                                  • Specific ListView Canvas on Canvas Home Page Always Loads Most Recent ListView, Not the One Specified

                                    I had mentioned this to ZOHO, but I mainly wanted to see if others in the Community are also facing this problem. I created a Canvas ListView for a Custom Module, and then created a Canvas Home page (technically on a tab item, but I'm not sure if that
                                  • Programmatic Itemized Expenses?

                                    It does not appear that it is possible to create itemized expenses programmatically (via the API)? Is this correct, or am I misunderstanding the situation?
                                  • Next Page