Zoho FSM | Create an event in monday.com Calendar for a Zoho FSM Work Order

Create an event in monday.com Calendar for a Zoho FSM Work Order

Use case: Create an event in the monday.com calendar when a work order is created
 
Step 1: Create a custom function
Step 2: Create a workflow rule

Step 1: Create a custom function 

Add a custom function that will create an event in Monday.com calendar from a Zoho FSM work order.
  1. Navigate to Setup > Automation > Functions and click Create Function.
  2. Enter the following details and click Save:
    1. Function Name: CreateEventInMonday
    2. Module: Work Orders
  3. In the Deluge Script Editor, enter the following script:

    try
    {
     board_id = "<Your board ID>";
     //info work_order;
     evdate = "";
     Due_Date = work_order.get("Due_Date");
     if(!Due_Date.isNull() && !Due_Date.isEmpty())
     {
      evdate = Due_Date;
     }
     else
     {
      predate1 = work_order.get("Preference").get("Preferred_Date_1");
      if(!predate1.isNull() && !predate1.isEmpty())
      {
      evdate = predate1;
      }
      else
      {
      predate2 = work_order.get("Preference").get("Preferred_Date_2");
      if(!predate2.isNull() && !predate2.isEmpty())
      {
      evdate = predate2;
      }
      else
      {
      evdate = "";
      }
      }
     }
     info evdate;
     wo_name = work_order.get("Name");
     summary_name = work_order.get("Summary");
     header_data = Map();
     header_data.put("Authorization","<API Token>");
     header_data.put("Content-Type","application/json");
     Territory_name = work_order.get("Territory").get("name").toString();
     info Territory_name;
     if(evdate != "")
     {
      event = {"query":"mutation {create_item (board_id:" + board_id + "item_name: \"" + wo_name + "\", column_values: \"{\\\"date\\\":\\\"" + evdate + "\\\", \\\"text\\\":\\\"My Text\\\"}\") {id}}"};
      info event;
      response = invokeurl
      [
      url :"https://api.monday.com/v2"
      type :POST
      parameters:event
      headers:header_data
      ];
      info response;
      item_id = response.toMap().get("data").toMap().get("create_item").get("id");
      data = {"query":"mutation {change_multiple_column_values(item_id:" + item_id + ", board_id:" + board_id + ", column_values: \"{\\\"date\\\" : {\\\"date\\\" : \\\"" + evdate + "\\\", \\\"time\\\" : \\\"18:00:00\\\"}}\") {id}}"};
      info data;
      response = invokeurl
      [
      type :POST
      parameters:data
      headers:header_data
      ];
      info response;
     }
     else
     {
      sendmail
      [
      from :zoho.adminuserid
      to :zoho.adminuserid
      subject :"Event is Not created"
      message :" Date field is Mandatory for event creation"
      ]
     }
    }
    catch (e)
    {
     info e;
     sendmail
     [
      from :zoho.adminuserid
      to :zoho.adminuserid
      subject :"Event is Not created"
      message :e
     ]
    }
For this custom function to work, the support for the escape character "\" needs to be enabled in your account. Please email Creator support regarding this.

In the above code snippet, replace the following with the actual values:
 
<Your board ID> Select the board to whose calendar you want to add the event. You can find the board ID in the URL.


 
<API Token> You can find the API token under the API tab at Account > Administration > Connections.
 

Step 2: Create a workflow rule 

Create a workflow that will add an event to the Monday.com calendar whenever a work order is created in Zoho FSM.
  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: CreateEventInMonday
    3. Description: Create an event in the Monday.com calendar when a work order is created



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



  4. Select the rule criteria as To all Work Orders and 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 use case 

Create a work order. A date is mandatory for event creation. So, ensure that you provide either of Due Date, Preferred Date 1, or Preferred Date 2 in the work order. If all three dates are empty, the event will not be created.
 
Also, please remove the existing Date column from your board and add it again.
 

 
The event will be added to your board's calendar.