Zoho FSM | Notify Changes in Work Order Status

Notify Changes in Work Order Status

Usecase: Notify the customer by email each time the status of the work order changes. Also, notify the customer when the payment has been done for the work order.
 
Follow the steps below to implement this use case:
Step 1: Create a custom function
Step 2: Create a workflow rule

Step 1: Create a custom function  

Create a custom function in Zoho FSM to notify the customer by email of the work order status.
  1. Navigate to Setup > Automation > Functions and click Create Function.
  2. Enter the following details and click Save:
    1. Function Name: NotifyCustomerAboutWOStatus
    2. Module: Work Orders
    3. In the Deluge Script Editor, enter the following script:

      /*----------------------------------------
      Fetching work order information
      ------------------------------------------*/
      work_order_id = work_order.get("id");
      Status = work_order.get("Status");
      work_order_resp = zoho.fsm.getRecordById("Work_Orders",work_order_id);
      work_order_data = work_order_resp.get("data").toMap();
      woName = work_order_data.get("Name");
      Billing_Status = work_order_data.get("Billing_Status");
      Grand_Total = work_order_data.get("Grand_Total");
      Summary = work_order_data.get("Summary");
      Email = work_order_data.get("Email");
      /*----------------------------------------
      Fetching Contact information
      ------------------------------------------*/
      ContactId = work_order_data.get("Contact").toMap().get("id");
      ContactName = work_order_data.get("Contact").toMap().get("name");
      contactResp = zoho.fsm.getRecordById("Contacts",ContactId);
      contactData = contactResp.get("data").toMap();
      Mobile = contactData.get("Mobile");
      /*----------------------------------------
      Fetching Company information
      ------------------------------------------*/
      company_name = organization.get("company_name");
      /*----------------------------------------
      Constructing message
      ------------------------------------------*/
      if(Status == "Completed")
      {
       message = "Write your Custom message for completed status";
      }
      if(Status == "New")
      {
       message = "Write your Custom message for new status";
      }
      if(Status == "In Progress")
      {
       message = "Write your Custom message for in progress status";
      }
      if(Status == "Cannot Complete")
      {
       message = "Write your Custom message for cannot complete status";
      }
      if(Status == "Scheduled Appointment")
      {
       message = "Write your Custom message for scheduled appointment status";
      }
      if(Status == "Cancelled")
      {
       message = "Write your Custom message for cancelled status";
      }
      if(Status == "Closed" && Billing_Status == "Paid")
      {
       message = "Dear " + ContactName + ", Thank you for trusting " + company_name + " and giving us an oppurtunity to help you with " + Summary + ". We have received your payment of $" + Grand_Total + ". We are looking forward to serve you again in future. Thank you";
      }
      if(Status == "Dispatched")
      {
       message = "Write your Custom message for dispatched status";
      }
      /*----------------------------------------
      Code to send Email
      ------------------------------------------*/
      sendmail
      [
       from :zoho.adminuserid
       to :Email
       subject :"Status of " + woName + " changed"
       message :message
      ]
      info "Email sent";

Step 2: Create a workflow rule  

Create a workflow rule in Zoho FSM to notify the customer by email each time the status of the work order changes. Also, notify the customer when the payment has been done for the work order.
  1. Go to Setup > Automation > Workflow Rules and click Create Workflow.
  2. Enter the following details, then click Next:
    1. Module: Work Orders
    2. Rule Name: Notify User about WO Status



  3. Select the rule trigger as Created or Edited and click Next.



  4. Select the rule criteria as To all Work Orders. Click Next.



  5. Click +Action and select Function.



  6. Select Existing Functions and click Next.



  7. Select the custom function created in the previous step.



  8. Click Save.

Testing the usecase  

Create a Work Order. Whenever the status of the work order changes, then the contact will be notified by email.