Delete subform rows based on mainform input

Delete subform rows based on mainform input

I took my first adventure in getting ChatGPT to write some code for me this weekend.

I want to ADD new rows, UPDATE existing rows and DELETE existing rows based on the input of a mulitselect lookup in the mainform. ChatGPT produced this for me which seems to work to ADD and UPDATE but then I got into a loop of doom with a very over-confident ChatGPT about whether it's possible to delete rows using script on success or whether I have to call a function to delete. So two questions: 
1. Is this code the best code for ADDING / UPDATING or can someone beat ChatGPT? 
2. what do I do about deleting the rows? Can anyone help me with the on success code / function to call? 

Thanks guys! 

mainRec = Participation[ID == input.ID];
if(mainRec != null)
{
subformRows = Participation_subform[Lookup_to_mainform == mainRec];
for each  selectedValue in mainRec.People_lookup
{
exists = false;
for each  sub in subformRows
{
if(sub.Name_lookup_subform == selectedValue)
{
// Already exists — update values directly
sub.Activity_lookup_subform=input.Activities_lookup;
sub.Service_subform=input.Service;
sub.Time_spent_subform=input.Time_spent;
sub.Date_subform=input.Date_field;
exists = true;
break;
}
}
if(!exists)
{
insert into Participation_subform
[
Lookup_to_mainform=mainRec
Name_lookup_subform=selectedValue
Activity_lookup_subform=input.Activities_lookup
Service_subform=input.Service
Time_spent_subform=input.Time_spent
Date_subform=input.Date_field
Added_User=zoho.loginuser
]
}
}
}




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






                                ご検討中の方

                                  • Recent Topics

                                  • Finding missing records

                                    I have a challenge and I am not really sure where to start with it. I can't find any similar threads on here, can anyone help: I have two forms, FormA and FormB. Both forms have records that contain a field called Job_Number. What I am trying to achieve
                                  • Zoho CRM - Option to create Follow-Up Task

                                    When completing a Zoho CRM Task, it would be very helpful if there was an option to "Complete and Create Follow-Up Task" in the pop-up which appears. It could clone the task you are closing and then show it on the screen in edit mode, all the user would
                                  • What is your opinion of the new UI?

                                    Hi Everyone, I would like to see what everyone thinks of the new Zoho One Dashboard. I don't get it, but perhaps I'm missing something. What are your thoughts?
                                  • Addin Support in Zoho Sheet

                                    Is there any addin support available in zoho sheet as like google marketplace to enhance productivity by connecting with other apps, providing AI data analysis, streamlining business processes, and more?
                                  • Scheduled Reports - Do not send empty report

                                    Hello, We are intensively using reports in the CRM, especially for sales managers.  When data is empty, they still receive an email. Can you add an option to avoid sending the report when data is empty?
                                  • Prevent Unapproved Quotes from Exporting to Zoho CRM Finance Module

                                    Is it possible to prevent unapproved quotes in Zoho Books from being exported from Zoho Finance module inside Zoho CRM?
                                  • ZOHO BOOKS - RECEIVING MORE ITEMS THAN ORDERED

                                    Hello, When trying to enter a vendor's bill that contains items with bigger quantity than ordered in the PO (it happens quite often) - The system would not let us save the bill and show this error: "Quantity recorded cannot be more than quantity ordered." 
                                  • CRM x WorkDrive: File storage for new CRM signups is now powered by WorkDrive

                                    Availability Editions: All DCs: All Release plan: Released for new signups in all DCs. It will be enabled for existing users in a phased manner in the upcoming months. Help documentation: Documents in Zoho CRM Manage folders in Documents tab Manage files
                                  • Updates for Zoho Campaigns: Merge tag, footer, and autoresponder migration

                                    Hello everyone, We'd like to inform you of some upcoming changes with regard to Zoho Campaigns. We understand that change can be difficult, but we're dedicated to ensuring a smooth transition while keeping you all informed and engaged throughout the process.
                                  • Zoho CRM App - Links

                                    Hi  Is there are plan for making Custom Links available in the Zoho CRM Android App? I can't see them being added? Thanks Gene
                                  • Sending email notifications based on language

                                    Hello. I would like to know how we can bypass the default notifications (which are just in English) for when a ticket is created/replied to/closed, to be in other languages, based on the language field in the ticket? I can create other email templates,
                                  • Custom Related List Inside Zoho Books

                                    Hello, We can create the Related list inside the zoho books by the deluge code, I am sharing the reference code Please have a look may be it will help you. //..........Get Org Details organizationID = organization.get("organization_id"); Recordid = cm_g_a_data.get("module_record_id");
                                  • Process between CRM and Campaigns to ensure double opt-in contacts?

                                    I would like to ask for a few clarifications to ensure we fully comply with best practices and legal requirements: According to the documentation (Zoho Campaigns CRM sync – Default option), the best and recommended way to sync contacts is by using the
                                  • What's New in Zoho Inventory | August – October 2025

                                    Hello customers, The last quarter has been incredibly productive! We've released a powerful slate of new features and enhancements in Zoho Inventory designed to give you better control, greater efficiency, and expanded functionality across your inventory
                                  • Let's Talk Recruit: Meet Zia, your all-in-one AI assistant (Part-2)

                                    Welcome back to Let’s Talk Recruit series. In Part 1, we introduced Zia and how AI is reshaping the way recruiters work. This time, we’re taking a closer look at how far Zia has come and how each update continues to simplify your everyday tasks. When
                                  • Zoho Developer - Feature Request Platform

                                    Zoho Developer is one of the most underatted platform in zoho ecosystem, however, it may just be what zoho needs to welcome more people to use Zoho Services. The more developers you have creating zoho creator applications and zoho extensions the more
                                  • Download a file from within a zoho creator widget

                                    I have a widget running in Zoho Creator , it displays uploaded documents in a table file, and I have added a download link in the view. ( The widget is created with html, css and javascript). I do not succeed in getting the download working. Do I have
                                  • Last/Previous month in relative date filter

                                    In the relative date filter, what is the difference between "Last 2 months" and "Previous 2 months"? So, if we are on 25-July, then is my understanding correct of the following: Last 2 months :=:      25-May~24 July Previous 2 months :=:     01-May~30-June Thanks.
                                  • Tags get removed from notes on mobile

                                    I don't know why this keeps happening even after all these app updates but if you log out and log back into the app or you reinstall it, all the tags you assigned to your notes get taken off, but if you go on the desktop version the tags are still there.
                                  • How to fetch custom fields for time entries in Zoho Project API v3

                                    In the previous Zoho Projects REST API, we were able to retrieve custom field details for time entries, including picklist options, using the endpoint: GET /restapi/portal/[PORTAL_ID]/timesheetcustomfields In the new Zoho Projects API v3, we tried using
                                  • Possible to connect Zoho CRM's Sandbox with Zoho Creator's Sandbox?

                                    We are making some big changes on our CRM so we are testing it out in CRM's Sandbox. We also have a Zoho Creator app that we need to test. Is it possible to connect Zoho CRM's Sandbox to Zoho Creator's Sandbox so that I can perform those tests?
                                  • VAT rates - exempt and out of scope

                                    Good Evening, UK based company here. I am a bit confused in respect of setting up VAT rates for exempt goods and services; at present I am simply leaving the VAT rate blank in the transactions in order to prevent any VAT appearing in the VAT return. When
                                  • Zoho is blocking emails I subscribe to from one sender

                                    About 4 months ago I stopped receiving newsletters that I subscribe to from @thedispatch.com. They tell me that zoho's server is blocking them. I've added them to my contacts list, but they're not even reaching my inbox. I don't know how to troubleshoot
                                  • Introducing Lead Capture: Empower exhibitors to capture leads effortlessly

                                    Events provide a great opportunity for exhibitors to generate awareness and engage with potential customers. Efficiently distributing attendee information to exhibitors through a seamless and secure way is of paramount importance. Introducing Lead Capture
                                  • Very long loading times | bad performance [ZOHO DC: EU]

                                    Hello there, we have recently noticed that the loading times have become extremely long when retrieving tickets and ticket details. For example, I open any ticket and get the following view. The subject and standard information (ticket owner, status etc.)
                                  • Work Order Creation Issue

                                    Dear Team, I would like to inquire about the daily limit for Work Order creation in Zoho FSM. Yesterday (02/05/2025) at around 6:30 PM GST, I attempted to create a Work Order, but I have been unable to do so since then. Please find the attached image
                                  • Double opt-in notifications and customizable confirmation messages for your webforms

                                    Dear CRM Community, We are excited to announce a major upgrade to our Webforms feature. You can now customize the confirmation message shown to your users who double opt-in from your webform and also customize your confirmation emails when they submit
                                  • Accessing shared mailboxes through Trident (Windows)

                                    Hi, I have a created a couple of shared mailboxes. The mailboxes are showing up on the browser based Zoho workplace, but I cannot seem to figure out how to access my shared inboxes through Trident (Windows). Am I missing something or is this feature not
                                  • URGENT: ChatGPT Extension Failing With “gpt-3 Access Error” (Priority Support)

                                    Appreciate support reviewing this urgently. I am a Priority Support member and need immediate clarification on a recurring issue involving the ChatGPT extensions inside Zoho Desk. Both extensions — including the version created and published by Zoho —
                                  • Zoho Desk iOS update: Custom buttons, follow/ unfollow option on tickets

                                    Hello everyone! In the most recent Zoho Desk iOS app update, we have brought in support to access the custom buttons configured on web app(desk.zoho.com). Using custom buttons you can seamlessly execute predefined actions directly from their mobile devices,
                                  • Zoho pdf suit

                                    Pl. design products with following feature: 1. Please add all features given in Ilovepdf website to work on pdf files. It is mandatory to use pdf in court work. 2. Courts have prescribed New Times Roman, pl. add this font as well 3. Indexing, signature
                                  • Zoho Not Working

                                    Today Zoho not wokring
                                  • Dynamically autofill fields with URL parameters

                                    I have a zoho form embedded in my organization's WP website. Our users find their account with a search tool, and then can select to open this page with the embedded form. The URL of the page holds the parameter that I need, but I cannot figure out how
                                  • User Automation: User based workflow rules & webhooks

                                    User management is an undeniable part of project management and requires adequate monitoring. As teams grow and projects multiply, manual coordination for updating users & permissions becomes difficult and can give way to errors. User automation in Zoho
                                  • Integrate Projects for Desk KB article release tasks

                                    Could you please look into the possibility of integrating project tasks for Zoho Desk article release processes? We are looking for an internal integration between Zoho Projects and Zoho Desk's KB article drafting, reviewing and releasing tasks. We could
                                  • Why is Zoho Meeting quality so poor?

                                    I've just moved from Office 365 to Zoho Workplace and have been generally really positive about the new platform -- nicely integrated, nice GUI, good and easy-to-understand control and customisation, and at a reasonable price. However, what is going on
                                  • Issue in Annual Leave

                                    We created a policy to credit 21 days at the Start of the Year An employee has taken 16 days of leaves thought the year, so we expect to see 5 Leaves remaining right? But Zoho People is Showing 12 Days of Leave Balance Available If we check the Leave
                                  • Use the searchBy parameter to find user by email address

                                    I'm trying to find a user is Zoho Desk via the Api. In the documentation I see that there is the possibility to add a searchBy parameter in the request. But I can't find how the search values should be formatted. I've tried multiple things and get either
                                  • Zoho CRM Community Digest - September 2025 | Part 2

                                    Hello Everyone! Mid-September vibes: fresh tips, smart hacks, and practical Zoho CRM updates all in one place. Let’s dive in. Product Updates: The All-New Address Field! The new Address field type makes it easier to capture complete addresses in one structured
                                  • Zoho Vault API: Create new Secrets

                                    Hello, I attempt to Post Secrets to the vault, since the encrypted entries are almost impossible to decrypt, since there is no documentation on how to decrypt them. Like with the lack of documentation on how to descrypt, there are missing information regarding on how to create new secrets/post secrets. Source: https://www.zoho.com/vault/api/#create-a-new-secret When I try to send JSON Informationen as a POST-Request I only receive the error message: {     "operation": {         "result": {             "error_code": "",
                                  • Next Page