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 Leadvar 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
}
Firma_w_bazie) from the Lead.accounts/{accountId}).kontrolka in the account.kontrolka (e.g., true to false or false to true).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.
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.
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,