Request for Assistance with Script for Updating a Custom Field in Accounts

Request for Assistance with Script for Updating a Custom Field in Accounts

Dear Zoho Support Team,

I have created the following script, intended to automate the update of a custom field called kontrolka in the Accounts module based on data from the Leads module.

Below is the script:

// Get the account ID from the Lead
var accountId = $lookup.Firma_w_bazie; // Check if the account ID exists if (accountId) { try { // Fetch account data using the account ID const account = await V7.api.get(`accounts/${accountId}`); // Retrieve the current value of the 'kontrolka' field const kontrolkaField = account.custom_fields.kontrolka; // Check if the 'kontrolka' field is defined if (kontrolkaField !== undefined) { // Toggle the value of the 'kontrolka' field const newValue = !kontrolkaField; // Update the account record with the new 'kontrolka' value await V7.api.patch(`accounts/${accountId}`, { custom_fields: { kontrolka: newValue } }); } } catch (error) { // Handle any errors that occur during the fetch or update process } } else { // Handle the case where no account ID is found }

Objective of the Script:

  1. Retrieve the account ID (Firma_w_bazie) from the Lead.
  2. Verify if the account ID exists.
  3. If the account ID exists, fetch the account details via the API (accounts/{accountId}).
  4. Check the value of the custom field kontrolka in the account.
  5. Toggle (invert) the value of kontrolka (e.g., true to false or false to true).
  6. Update the account record with the new value for kontrolka using the API (accounts/{accountId}).

The primary purpose of this script is to create a simple toggle mechanism for the kontrolka field in a related account record.

Real Objective:

The ultimate goal of this script is to trigger a change on the Account record because such a change automatically propagates updates from the Account record to the Lead record. This is crucial for my process since there are nearly 30 custom fields in the Account that need to sync with the corresponding fields in the Lead. Manually updating each field individually would be cumbersome, so this automation is intended to handle it efficiently.

Problem:

The script does not work as expected, and I am unable to determine at which step the process fails. There are no error messages, and the data in the Accounts module is not being updated.

Could you please assist me in identifying the issue? Is there something wrong with the logic of my script, or do I need to adjust my system configuration?

I would greatly appreciate any guidance or suggestions to resolve this issue.

Thank you in advance for your support.

Best regards,

Katarzyna Ochnik
katarzyna.ochnik@medidesk.com

    Access your files securely from anywhere







                            Zoho Developer Community




                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                  • Ask the Experts



                                                            • Sticky Posts

                                                            • Kaizen #222 - Client Script Support for Notes Related List

                                                              Hello everyone! Welcome to another week of Kaizen. The final Kaizen post of the year 2025 is here! With the new Client Script support for the Notes Related List, you can validate, enrich, and manage notes across modules. In this post, we’ll explore how
                                                            • Kaizen #217 - Actions APIs : Tasks

                                                              Welcome to another week of Kaizen! In last week's post we discussed Email Notifications APIs which act as the link between your Workflow automations and you. We have discussed how Zylker Cloud Services uses Email Notifications API in their custom dashboard.
                                                            • Kaizen #216 - Actions APIs : Email Notifications

                                                              Welcome to another week of Kaizen! For the last three weeks, we have been discussing Zylker's workflows. We successfully updated a dormant workflow, built a new one from the ground up and more. But our work is not finished—these automated processes are
                                                            • Kaizen #152 - Client Script Support for the new Canvas Record Forms

                                                              Hello everyone! Have you ever wanted to trigger actions on click of a canvas button, icon, or text mandatory forms in Create/Edit and Clone Pages? Have you ever wanted to control how elements behave on the new Canvas Record Forms? This can be achieved
                                                            • Kaizen #142: How to Navigate to Another Page in Zoho CRM using Client Script

                                                              Hello everyone! Welcome back to another exciting Kaizen post. In this post, let us see how you can you navigate to different Pages using Client Script. In this Kaizen post, Need to Navigate to different Pages Client Script ZDKs related to navigation A.


                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator 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


                                                                                            Zoho Show Resources

                                                                                              Zoho Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ



                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方