Creating an audit log of all changed fields

Creating an audit log of all changed fields

I'm trying to create an audit log to track changes made to any field in a form. It's set to work on Validation on form submission. I've tried using the trusty old ChatGPT but it's getting confused too! 

Can anyone point me in the right direction please? I'm getting an error on line 8, improper statement error might be due to missing ; at end of line or incomplete expression. 

// Get the ID of the current record
recordID = input.ID;

// Get the list of fields in the form
fieldsToTrack = getFieldNames();

// Loop through the fields to track
for each field in fieldsToTrack
{
    // Get old and new values
    oldValue = ifnull(old.get(field), "");
    newValue = ifnull(input.get(field), "");

    // Check if the value has changed
    if (oldValue != newValue)
    {
        // Add a new entry to the Activity log form
        logEntry = insert into Activity
        [
            Date_Time = zoho.currenttime,
            Field_Name = field,
            Old_Value = oldValue.toString(),
            New_Value = newValue.toString(),
            User = zoho.loginuser,
            Record_ID = recordID
        ];
    }
}

    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