Tip 8 : How to dynamically add rows to a subform via script.

Tip 8 : How to dynamically add rows to a subform via script.



Hi everyone,

 

A fortnight has gone by, and we are back with a new tip that would help you dynamically add rows to a subform via script. 

To understand how to do this, let's put ourselves in the shoes of an event manager. As an event manager, we need to regularly keep track of on-going events and the number of registrations received for each of the events. 

For this we need to create a form to record the details of all our events. Let's name this form as Events. This form would have the following fields: Event Name and Even Date. 


Now to get more registrations, we need to create a stateless form called Register for an Event Form which can be published and embedded in our blogs and websites. It would help us to record the details of all the attendees enrolling for our events. Here, we can even customize the submit button to “Register Now”
 

But, how do we fetch the attendee details (from the Register for an Event form) and link it to events listed in the All Events report?

For this we need to create another form called Attendees Details which would be added as a subform in our main form — Events


Here, Selected Event field would be a Lookup from the Events Form. For which you need to choose "Existing Relation", select the subform and name the Lookup field as "Selected Event". (This is how a bidirectional relationship is created between two forms. For more details click here)

Now, we need to fetch data from the Register for an Event Form on click of the Register Now button and dynamically add it to the subform in the All Events report.

Let's see how to do this:

For this, let's use the Add Record task on click action of Register Now button to push the data collected along with its Lookup value (Selected Event). 
  1. rec = insert into Attendees_Details
  2. [
  3.   Added_User=zoho.loginuser
  4.   Selected_Event=input.Select_the_event
  5.   Attendee_Name=input.Name
  6.   Phone_Number=input.Phone_Number
  7.   Accomodation_Needed=input.Accomodation_Needed
  8. ];

Note: The primary key is the bidirectional Lookup Selected Event for which we are passing the value of the event selected by the Attendees in Register for an Event Form.

That's it, whenever an attendee registers for an event, the attendee details will get auto-populated in the subform in All Events Report. You can now easily view the attendee details for each of your events as given below.


Hope you got a fair idea on how to dynamically Add Rows to a subform via script. Keep watching this space for more such tips.



    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