Rodger's helpful deluge scripts #4 - Bulk updating records using a deluge function

Rodger's helpful deluge scripts #4 - Bulk updating records using a deluge function

One of this things I love about Zoho is that there's so many ways to accomplish something. Want to mass update some records? Sure, we have the Mass Update function to update a single field. Need to update more than 1 field? Sure, we have she Sheet view, but what if you need to incorporate logic decisions or calculations into your record update?

You could use sheet view, but that's limited to 100 records at a time, and what if there's multiple logic decisions to be made? Well, you use a deluge function.

This is the function I use when dealing with relatively small numbers of records. It can work well up to a couple of thousand records:

Firstly you're going to create a standalone function with the following arguments:

v_module (string data type)
v_records (integer data type)

Then we're going to use the following code:

  1. // Create a list of pages based on the number of records in the module. This will take the  number of records, v_records, 
  2. // divide it by 200 (200 records per page) and then round up to the nearest whole number. It will then use this number to repeat the text "1,"
  3. // and finally, it will remove the last "," and convert the string into a list

  4. l_pages = repeat("1,",(v_records/200).ceil()).removeLastOccurence(",").toList();
  5. l_bulkUpdate = List(); // Create a list to hold the records for the bulk update
  6. v_page = 1; // set the first page number
  7. for each page in l_pages
  8. {
  9. l_records = zoho.crm.getRecords(v_module,v_page,200);
  10. for each record in l_records
  11. {
  12. m_record = Map();
  13. m_record.put("id", record.get("id"));
  14. m_record.put("updated", true); // Create a temporary checkbox in your module to track whether the record has been updated
  15. //
  16. // insert your code here
  17. //
  18. l_bulkUpdate.add(m_record);
  19. if ( l_bulkUpdate.size() == 100 ) 
  20. {
  21. bulkUpdate = zoho.crm.bulkUpdate(v_module, l_bulkUpdate);
  22. info "Bulk Update: " + bulkUpdate;
  23. l_bulkUpdate.clear(); // Clears the bulk update list after sucessful bulk update
  24. }
  25. }
  26. v_page = v_page + 1; // Index the page number by 1
  27. }
  28. if ( l_bulkUpdate.size() > 0) 
  29. {
  30. bulkUpdate = zoho.crm.bulkUpdate(v_module, l_bulkUpdate); // Final bulk update if the list size is greater than zero but less than 100
  31. info "Bulk Update: " + bulkUpdate;
  32. }

Now put your logic in where it says "// insert your code here" then you can save and execute.

Because we use the put the module name in a variable, you can use this code for any module and will be prompted for the module name and the record count when you click "Save and Execute"

This comes with a warning however - DO NOT TRY THIS IN PRODUCTION IF YOU'RE TESTING YOUR CODE. ALWAYS TEST THIS IN SANDBOX FIRST BEFORE USING IT IN PRODUCTION!!

Also, test out your code on a single record before testing out your bulk update. That way you won't have to undo a huge mess if something goes wrong.

This is by no means the ONLY way to bulk update records using a deluge function and will not work if you have tens or hundreds of thousands of records.

    Access your files securely from anywhere

        Zoho Developer Community







                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation
                                              • Sticky Posts

                                              • Context and convenience just got better with Zia's email intelligence

                                                Dear Customers, We hope you're well! We are in 2024, and email as a tool is only getting more powerful each day. While it enables seamless daily correspondences, we are here with a set of abilities that will enhance your user experience and save several
                                              • Investigate your losses using VoC's root-cause analysis

                                                Dear Customers, We hope you're well! Loss and customer churn are inevitable in any business, even for historically successful ones. While it's never pleasant to see customers leave, it's crucial for businesses to identify the triggers behind these losses
                                              • Enrich your CRM data and keep them updated

                                                You spend a lot of your time and efforts in generating quality leads for your business. While generating leads is a challenge in itself, the real deal begins when sales reps try to nurture these leads and convert them as customers. So how equipped is your sales team with information about your leads matters a lot.  For example, you might be using webforms to generate leads and collect customer information from your website. The lesser your webform fields are, the more your sign-ups right? From optimizing
                                              • Introducing Color Coding of Picklist Values

                                                Dear Everyone, Greetings!! Zoho CRM is uplifting the user experience. Recently, we had some notable aesthetic improvements in CRM like Kanban View UI enhancement, New List view UI enhancement, color coding of tags, and color coding of picklists in meetings.
                                              • Introducing Built-In Telephony in Zoho CRM

                                                Dear All, Greetings! We are excited to introduce the bespoke "Built-In Telephony" in Zoho CRM. Built-in telephony is designed to allow organizations to build their own telephony framework, manage subscriptions and payments, generate call reports, and


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns 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





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now