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
        ];
    }
}
    Zoho Desk Resources

    • Desk Community Learning Series


    • Digest


    • Functions


    • Meetups


    • Kbase


    • Resources


    • Glossary


    • Desk Marketplace


    • MVP Corner


    • Word of the Day


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




                              ご検討中の方