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


                                              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


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • 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