Zoho FSM | Email Customers the Attachments in Service Appointment Notes

Email Customers the Attachments in Service Appointment Notes

Usecase: On service appointment completion, email the attachments in the service appointment notes to the customer.
 
Follow the steps below to implement this usecase:
Step 1: Create a connection for Zoho FSM
Step 2: Create a custom function
Step 3: Create a workflow rule

Step 1: Create a connection for Zoho FSM  

To use the Zoho FSM APIs via the invokeURL task in the custom function, you need to create a connection for Zoho FSM. To do so:
  1. Navigate to Setup > Developer Space > Connections and click Create Connection.



  2. Under the Default Services tab, search for and click Zoho FSM.



  3. Enter the following details and click Create And Connect.
    1. Connection Name: ZFSM
      The Connection Link Name will be populated automatically.
    2. Disable Use Credentials Of Login User.
    3. Select the Scope ZohoFSM.files.READ
  4. Click Connect in the authentication page.



  5. Click Accept in the Authorization page.


In the custom function, where the FSM API is used via the invokeURL task, use this Connection Link Name.

Step 2: Create a custom function

Create a custom function that will email the attachments in service appointment notes to the customer.
  1. Navigate to Setup > Automation > Functions and click Create Function.
  2. Enter the following details and click Save:
    1. Function Name: SendAttachments
    2. Module: Service Appointments
    3. In the Deluge Script Editor, enter the following script:
id = service_appointment.get("id");
contactId = service_appointment.get("Contact").get("id");
contactResp = zoho.fsm.getRecordById("Contacts",contactId);
email = contactResp.get("data").toMap().get("Email");
related_resp = zoho.fsm.getRelatedRecords("Notes","Service_Appointments",id);
 
if(related_resp.isEmpty())
{
 info "No notes added !!!";
}else
{
 related_resp_list = related_resp.get("data").toList();
 for each each_related_resp in related_resp_list
 {
 each_related_resp_map = each_related_resp.toMap();
 attachmentsResp = each_related_resp_map.get("$attachments");
 
 if(attachmentsResp.isNull()){
  info "No attachment present in the Note !!!";
 }else{
  attachments_list = each_related_resp_map.get("$attachments").toList();
 
 for each  attachment in attachments_list
 {
  file_id = attachment.get("$file_id");
  fileResp = invokeurl
  [
   type :GET
   connection:"zfsm"
  ];
  sendmail
  [
   from :zoho.adminuserid
   to :email
   subject :"Zoho FSM Notes Attachments"
   message :"Please find attached the files in service appointment Notes."
   Attachments :file:fileResp
  ]
 }
 }
 }
}

Step 3: Create a workflow rule  

Create a workflow rule in Zoho FSM to automatically email the attachments in service appointment notes to the customer on service appointment completion.
  1. Go to Setup > Automation > Workflow Rules and click Create Workflow.
  2. Enter the following details, then click Next:
    1. Module: Service Appointments
    2. Rule Name: Send Attachments
    3. Description: On service appointment completion, email the attachments in service appointment notes to the customer.



  3. Select the rule trigger as Edited and click Next. Select the checkbox Repeat this workflow whenever a Service Appointment is edited.



  4. Select the rule criteria as Only to the Service Appointment matching certain conditions and add the condition Status is Completed. 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    

  1. Create a Service Appointment.
  2. Add Notes with attachments to the service appointment.
  3. Click Complete Work for the service appointment.