Zoho FSM | Create an event in Microsoft Calendar for a Service Appointment

Create an event in Microsoft Calendar for a Service Appointment

Use case: Whenever a service appointment is created in Zoho FSM, create an event in Microsoft Calendar.
 
Follow the steps below to implement this use case:
Step 1: Create a connection for Microsoft Calendar
Step 2: Create a custom function
Step 3: Create a workflow rule

Step 1: Create a connection for Microsoft Calendar  

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



  2. Under the Default Services tab, select Office 365.



  3. Do the following and click Create And Connect.
    - Enter the Connection Name as Microsoft Calendar. The Connection Link Name will be automatically populated.
    - Disable Use Credentials Of Login User. If this is disabled, the connection will utilize the credentials of the connection owner.
    - Select the Scopes Calendars.ReadWrite, and offline_access.



  4. Click Connect in the authentication page.



  5. Click Connect in the Authorization page.



  6. Sign in to your account.



  7. Click Allow in the Authorization page.



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


Step 2: Create a custom function    

Create an event in Microsoft Calendar from a service appointment.
  1. Navigate to Setup > Automation > Functions and click Create Function.



  2. Enter the following details and click Save:
    1. Function Name: CreateEventInMicrosoftCalendar
    2. Module: Service Appointments
    3. In the Deluge Script Editor, enter the following script:

      try

      {

      summary_name = service_appointment.get("Summary").toString();

      scheduled_start = service_appointment.get("Scheduled_Start_Date_Time").toString();

      scheduled_end = service_appointment.get("Scheduled_End_Date_Time").toString();

      work_order_name = service_appointment.get("Appointments_X_Services").get(0).get("Work_Order").get("name").toString();

      appointment_name = service_appointment.get("Name").toString();

      header_data = Map();

      header_data.put("Content-Type","application/json");

      eventinput = {"subject":summary_name,"body":{"contentType":"TEXT","content":"work_order_name:" + work_order_name + "- appointment_name:" + appointment_name},"start":{"dateTime":scheduled_start,"timeZone":"UTC"},"end":{"dateTime":scheduled_end,"timeZone":"UTC"}};

      info eventinput;

      response = invokeurl

      [

      url :"https://graph.microsoft.com/v1.0/me/events"

      type :POST

      parameters:eventinput.toString()

      headers:header_data

      connection:"microsoftcalendar"

      ];

      info response;

      }

      catch (e)

      {

      info e;

      }

Step 3: Create a workflow rule

Whenever a service appointment is created in Zoho FSM, create an event in Microsoft Calendar.
  1. Navigate to Setup > Automation > Workflow Rules and click Create Workflow.
  2. Enter the following details, then click Next:
    Module: Service Appointments
    Rule Name: Create Event in Microsoft Calendar
    Description: Create an event in Microsoft Calendar when a new service appointment is created



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



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



  5. Click +Action and select Function.



  6. Select Existing Functions and click Next.



  7. Select the function created in the previous step.



  8. Click Save.


Testing the use case

Create a Service Appointment. An event will be created in your calendar.