Passing a form object to a function

Passing a form object to a function

Suppose I have a sort_order field in multiple tables and I want to increment it by +1 onCreate of a new record.

Is there a way to pass the form object as an argument into the function to keep things DRY?

The following function from Zia works, but I'd need to repeat it for every form, which results in a lot of code duplication.

int incrementByOne()
{
// Fetch the record with the highest sort_order from MyForm 
latestRecord = MyForm[ID != 0] sort by sort_order desc range from 0 to 0;

// Initialize nextSortOrder to 1 by default
nextSortOrder = 1;

// Check if a record exists and has a valid sort_order
if(latestRecord.count() > 0) {
if(latestRecord.sort_order.isValidObject()) {
nextSortOrder = latestRecord.sort_order + 1;
}
}
return nextSortOrder;
}


      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 コンテンツ



                                ご検討中の方