Client Script: Confirmation Alert before Deleting Critical Data in Zoho CRM

Client Script: Confirmation Prompt Before Deleting Critical Data in Zoho CRM

Requirement Overview

A Zoho CRM user wants to have a Confirmation Alert to ensure having a double confirmation before Clearing data from the Sensitive & Critical fields.

Use-case

Bank which uses Zoho CRM to manage client interaction in an effective way. It also keep customer’s sensitive data such as Personal Information, Account Number, Credit Card number, Security numbers, etc. Protecting this data is not just a security best practice—it is also a regulatory requirement governed by financial laws and data protection standards like GDPR.

Users often update, modify, or clear data as part of routine operations. A single accidental action(i.e. such as clearing a field), could result in irreversible data loss.

To mitigate this risk, a Double Confirmation Mechanism is implemented via Client Scripts in the CRM interface. This enables to triggers a confirmation pop-up alert before executing any data-clearing action on sensitive fields.
Alert
Why It is Important:
  1. Data Protection 
  2. Compliance Assurance
  3. Mitigated Risk
  4. Accident Prevention
  5. Enhanced Confidence
Info

Permissions & Availability

-> Users with the Manage Extensibility can configure & setup Client Script.
-> Users with the Manage Sandbox permission can manage the sandbox and test this use-case.

Configuration

Now, let us create a Client Script on Edit Page of a Lead Module for a specific field(i.e. Credit Card Number). As an example, whenever the field modifies to Empty, script will throw a Pop-up to get Confirmation from end User before proceeding further.

Follow the steps below to configure the Client Script for this use case:

1) Provide the basic information, like Name and Description based on script purpose.

2) In the Category Details section, please choose the following:

Category as Module.
Page as Edit.
Module as Leads.
* Choose the required Layout.

3) In the Event Details section, please choose the following:

Type as a Field Event.
* Choose the required Field from the drop-down.
Event as onChange.

The Code

  1. //fetching record details and getting privious value of field(Credit Card Number)
  2. recDetails = $Page.record;
  3. creditCardPrevValu = recDetails.Credit_Card_Number;
  4. console.log(creditCardPrevValu);

  5. //fetching same field with current value(after making update)
  6. var currentField = ZDK.Page.getField('Credit_Card_Number');
  7. const currentFieldVal = currentField.getValue();
  8. console.log(currentFieldVal);

  9. //checking if field value is empty or not
  10. if (currentFieldVal == "") {

  11.     //showing confirmation pop-up in UI to proceed further
  12.     confAlert = ZDK.Client.showConfirmation('Are you *sure*?', 'Yes. Got it!', 'Nope');

  13.     //if selected 'Nope', then updating field with previous value using variable 'creditCardPrevValu'
  14.     if (confAlert == false) {
  15.         // console.log("entered");
  16.         var creditCardField = ZDK.Page.getField('Credit_Card_Number');
  17.         creditCardField.setValue(creditCardPrevValu);
  18.     }
  19. }
  1. Code Explanation

-> Script will fetch the current opened record and get field (Credit Card Number) previous value which was present before triggering Client Script and store in a variable.

-> Then, it will fetch the same field value with current data (modified by end user) and store in a variable.


-> Then, it checks if field (Credit Card Number) is empty or not with current data (stored in variable - currentFieldVal). 


-> If field is Empty - then it shows the confirmation pop in UI to proceed further by end user. If user clicks on Yes, then no action required. If user clicks on No, then it updates the field with previous value(stored in variable - creditCardPrevValu).

Working Demo - Screencast


Idea
-> User can configure the same setup for Detail Page as well.
-> Also, user can setup this for multiple fields(based on Page Event -> OnChange) on a page to mitigate such data loss risk.

AlertTo ensure a smooth implementation, we recommend configuring and testing the setup in the sandbox environment before deploying it to production.

TIPS - Avoid Common Errors

-> Ensure to use the correct API Names for both Module & Fields in the script.

-> To ensure you get the intended output, we would suggest you to add logs() || console.log() to each variable to check the output for seamless functionality. i.e., you could view the output in the "Messages" tab within Client Script IDE for each logs() print. To view console logs, you could follow - "Right Click on browser page >> Inspect >> Console".

-> In case the expected functionality does not work, then try the script by verifying each output & loop along with that, cross-verify the syntax of each ZDK Client/CRM API method in the provided sample help document. 

InfoSample Scripts for each ZDK Client/CRM APIs methods - Help Reference

Notes
Notes: Refer to the following Guide - Article to learn the best practices for Optimizing the code and various ways to deploy Client Script across Zoho CRM.



If you need any further clarifications, please don’t hesitate to contact partner-support@zohocorp.com.

Notes
Additionally, we kindly ask all Europe and UK Partners to reach out to partner-support@eu.zohocorp.com.