Iterate a set of code n times | Creator Simplified
Hey Creators—we're back with another edition of Creator Simplified!
Objective
Generate subform rows with serial numbers based on user input in a field.
Use case
Assume an event is being organized in an organization, and HR needs the list of participants from each team. When the team leader inputs the number of participants on the event registration form, the specified number of subform rows are generated along with serial numbers.
How to achieve this
1. Create a form named Event Details. Add relevant fields and a number field named No.of Participants.
2. Add a subform (either a blank form or an existing form) named Participant Details, with necessary fields to collect participant information.
3. Configure a form workflow for the Event Details form on user input of the No.of Participants field.
4. Copy and paste the code given below. The code has been broken down for easy understanding.
- //Run the action when no.of participants are mentioned
- if(input.No_Of_Participants != null)
- {
- //Clear existing data
- input.Participant_Details.clear();
To iterate n number of records, we need to create a list with dynamic values. Since we cannot directly create a dynamic list, here's a workaround:
First, take a string value; let's say "t". Next, use the leftpad() function to return the text "t" left-padded with white spaces that together equates to the count of participants entered.
Next, replace each whitespace with "t,". The comma separates each replaced t and helps convert it into a list. Finally, use the toList() function to convert all these values to a list.
- //Create a dynamic list with number of participants mentioned
- no_of_participants = "t".leftpad(input.No_Of_Participants).replaceAll(" ","t,").toList();
Create a collection variable to store subform data, then iterate through the list of participants using a for loop to create, serialize, and insert subform rows into the collection variable.
- col = Collection();
- sl = 1;
- for each participant_rec in no_of_participants
- {
- rows = Event_Details.Participant_Details();
- rows.Sl_No=sl;
- col.insert(rows);
- sl = sl + 1;
- }
- input.Participant_Details.insert(col);
- }
And that's all for this post! We hope this workaround helps you quickly resolve your real-time requirements.
Feel free to share your questions, thoughts, or suggestions in the comment box.
Keep an eye on this space for more useful posts in the future!
Access your files securely from anywhere
Zoho Developer Community
Deliver unforgettable customer experiences
Deliver unforgettable customer experiences
New to Zoho Marketing Plus?
Everything you need to run your marketing
New to Zoho Marketing Plus?
Everything you need to run your marketing
Zoho Desk Resources
-
Desk Community Learning Series
-
-
-
-
-
-
-
-
-
Sticky Posts
Introducing Creator Simplified: An exclusive learning series to enhance your app development skills
Hey Creators! Welcome to Zoho Creator's new learning series, Creator Simplified. In this series, we'll dive into real-world business use cases and explore how to translate your requirements into solutions in your Creator application. You can also expect
ANZ In-Person Zoho User Group Meetups: Focusing on Zoho Creator & Zoho Flow (September 2024)
Hello, Zoho Community! Calling all Zoho users in Australia! We're thrilled to announce the next series of Zoho User Group (ZUG) Meetups, continuing the success of our previous sessions. These meetups are a great opportunity to learn, network, and engage
[SESSION ENDED] Ask the Experts #07| Live Q&A: Building workflows with Blueprint in Zoho Creator |
Hello, Post the release of Zoho Creator Blueprint last month, we're happy to tell you that we'll be launching a new 'Ask the Experts' session on 16th September (Thursday) this month focussing on creating blueprints in Zoho Creator. The session will be
Zoho Creator Community Webinars | October - November 2020 [Completed]
Hello everyone, I’m happy to announce that Zoho Creator is hosting a new Community Webinar Series starting this October. This series is a learning initiative aimed at our developer community, where every session will take spotlight use cases focused on
Community Learning Webinar - Zoho Creator Blueprint & other release updates | July 29, 2021
Dear developers, This June, the Creator team unveiled a slew of updates including UI enhancements to the Detail View of reports, an new capabilities in Data Import and Connections, and most important of all, the release of Blueprint in Creator. Customize
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
Zoho Show Resources
Writer Get Started. Write Away!
Writer is a powerful online word processor, designed for collaborative work.