Email Customer the Job Sheets when a Service Appointment is Completed

Email Customer the Job Sheets when a Service Appointment is Completed

Use case: When a service appointment is completed, email the customer the completed job sheets in the service appointment.
 
Follow the steps below to implement this use case:
Step 1: Create a connection
Step 2: Create a custom function
Step 3: Create a workflow rule

Step 1: Create a connection

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.modules.JobSheets.READ
  4. Click Connect in the authentication page.



  5. Click Accept in the Authorization page.

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

Step 2: Create a custom function 

Create a custom function in Zoho FSM to email the customer the completed job sheets of a service appointment.
  1. Navigate to Setup > Automation > Functions and click Create Function.
  2. Enter the following details and click Save:
    1. Function Name: SendJobsheetsToCust
    2. Module: Service Appointments
    3. In the Deluge Script Editor, enter the following script:

try

{

file_list = list();

Appointment_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");

info email;

related_resp = invokeurl

[

url :"https://fsm.zoho.com/fsm/v1/Service_Appointments/" + Appointment_id + "/Job_Sheets"

type :GET

connection:"zfsm"

];

if(!related_resp.isNull() && !related_resp.isEmpty())

{

jobsheetResp = related_resp.get("data");

if(jobsheetResp.isNull() || jobsheetResp.isEmpty())

{

info "No jobsheets present in the SA !!!";

}

else

{

jobsheet_list = related_resp.get("data").toList();

for each  jobsheet in jobsheet_list

{

Status = jobsheet.get("Status");

if(Status.equalsIgnoreCase("Completed"))

{

filename = jobsheet.get("Name");

file_id = jobsheet.get("id");

if(!file_id.isNull() && !file_id.isEmpty())

{

fileResp = invokeurl

[

url :"https://fsm.zoho.com/fsm/v1/Job_Sheets/" + file_id + "/actions/download?type=pdf"

type :GET

connection:"zfsm"

];

filename = filename + ".pdf";

fileResp.setFileType("pdf");

fileResp.setFileName(filename);

file_list.add(fileResp);

}

}

}

}

}

if(!file_list.isEmpty())

{

sendmail

[

from :zoho.adminuserid

to :email

subject :"Jobsheets "

message :"PFA"

Attachments :file:file_list

]

}

}

catch (err)

{

info err;

sendmail

[

from :zoho.adminuserid

to :zoho.adminuserid

subject :"Error in executing the code"

message :err

]

}

Step 3: Create a workflow rule

Create a workflow rule in Zoho FSM to automatically email to the customer the completed job sheets of a service appointment when the service appointment is Completed.
  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: SendJobsheetsToCust
    3. Description: On service appointment completion, email the job sheets in service appointment to the customer.



  3. Select the rule trigger as Edited. Select Specific field(s) gets modified and add the condition When Status is modified to the value Completed. Check Repeat this workflow whenever a Service Appointment is edited. Click Next.



  4. Select the rule criteria as To all Service Appointments. Click Next.



  5. Click +Action and select Functions.



  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. Complete a job sheet in the service appointment.
  3. Click Complete Work for the service appointment.
    The job sheets will be emailed to the contact in the service appointment.