Disable Action Items after n times

Disable Action Items after n times

Requirement 

A custom action created using an Action item on a report has to be disabled after it is triggered three times.

Use Case 

We have an app to maintain customer invoices. After an invoice is created, the staff can email the invoice to the customer with the click of a button. However, to avoid sending multiple emails, the button has to be disabled if it is clicked three times, which means a maximum of three emails can be sent for each customer.
See how it works

 Steps to follow 

1.  Create two forms with the following details:
Form
Form Link Name
Field Type
Field Name
Field Link Name
Customers
Customers
Name
Customer Name
Customer_Name
Email
Customer Email
Customer_Email
Invoices
Invoices
Lookup(Customers)
Customer
Customer
Date
Invoice Date
Invoice_Date
Subform
  • Single Line
  • Number
Order
  • Product
  • Quantity
Order
  • Product
  • Quantity
 
 
Currency
Total Amount
Total_Amount
 
 
Number
Number of emails sent
Number_of_emails_sent
 
The Number of emails sent field is used to disable the button once the limit is reached. Set an initial value 0 to it.

2. Let's disable the Number of emails sent field so that it cannot be edited manually. Create a workflow with the following details.

3. Click Add New Action and select Disable fields. Next, select the field Number of Emails sent.               

4. Now, let's create an invoice template that needs to be sent to the customers. Navigate to Settings > Record Templates, and create a record template by selecting From a template.

5.  Select the first template under Invoices.

6. Select the base form as Invoices as displayed below, and name it ' Invoice '.
 
We have made minor changes to the template and created the following template.

7. Next, let's add an action item that will help us send emails on the click of a button. Select All Invoices report, and click + under Quick View > Actions.

8. Create an action item with the following details. Click CREATE WORKFLOW.

9. Click Add New Action , then select Deluge Script.

10.  Click Create your own , then save the following script.
  1. // Increment the Number_of_emails_sent field so that it can be used as counter till its value reaches 3
  2. input.Number_of_emails_sent = input.Number_of_emails_sent + 1;
  3. // Fetch the email address of the customer to which the invoice will be sent
  4. customer_record = Customers[ID = input.Customer];
  5. customer_email=customer_record.Customer_Email;
  6. // Send an email to the fetched email address with the invoice template
  7. sendmail
  8. [
  9. from :zoho.adminuserid
  10. to :customer_email
  11. subject :"Zylker invoice"
  12. message :"Please find the invoice for your recent purchase"
  13. Attachments :template:Invoice:Invoices input.ID as PDF
  14. ]
15. C lick CREATE to save the action item with the script.

16.  Now, we will list the action item in the report. Click All Invoices report > Configure Fields for Web.


17. Click + Add Fields and select the  Send Email button.

The button will now be listed in the Invoices report.

  See how it works         

 

Points to note