Zoho FSM | Create a Request in Zoho FSM from a Ticket in Zoho Desk

Create a Request in Zoho FSM from a Ticket in Zoho Desk

Use case: Create a Request in Zoho FSM when the status of a Zoho Desk ticket changes to Moved to FSM. The created request will have a custom field with the ID of the Zoho Desk ticket from which it was created.
 
Step 1: Create a custom status in Zoho Desk
Step 2: Create a connection for Zoho FSM in Zoho Desk
Step 3: Create a custom function
Step 4: Create a workflow rule
Step 5: Create a custom field

Step 1: Create a custom status in Zoho Desk

Create a custom status Moved to FSM in Zoho Desk.
  1. Navigate to Setup > Customization > Ticket Status and click Add Status.



  2. In the Add New Ticket Status form, do the following and click Save.
    1. Status Name: Moved to FSM
    2. Status Type: Closed

Step 2: Create a connection for Zoho FSM in Zoho Desk

To create a connection for Zoho FSM that can be used in Zoho Desk for invoking the Zoho FSM APIs, do the following:
  1. Navigate to Setup > Developer Space > Connections and click Create Connection.



  2. In the Create Connection page, select the Custom Services tab and click Create New Service.



  3. In the Create Service page, enter the following details and click Create Service.
    1. Service Name: Zoho FSM
      The Service Link Name will be automatically populated.
    2. Authentication Type: OAuth2
    3. Parameter Type: Header
    4. Generated Client ID, Client Secret
    5. Authorize URL: https://accounts.zoho.com/oauth/v2/auth?access_type=offline&prompt=consent
    6. Access Token URL: https://accounts.zoho.com/oauth/v2/token
    7. Refresh Token URL: https://accounts.zoho.com/oauth/v2/token
    8. Scope: ZohoFSM.modules.all
      Provide values for Scope Display Name.



  4. Do the following and click Create And Connect:
    1. Connection Name: FSMConnection
    2. Select the Scopes ZohoFSM.modules.all



  5. Click Connect in the authentication page.



  6. Click Accept in the authorization page.


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

Step 3: Create a custom function

Create a custom function to create a Request in Zoho FSM from a Ticket in Zoho Desk.
  1. Navigate to Setup > Automation > Workflows > Custom Functions and click New Custom Function.



  2. In the Configure Custom Function page, click Write your own.



  3. In the Add New Custom Function page, do the following:
    1. Select the module Tickets
    2. Enter the Name as CreateRequestInFSM
    3. Click Edit Arguments



  4. In the Edit Arguments overlay, enter the following and click Done:
    1. Method Name: CreateRequestInFSM
    2. Name: ticket_id
    3. Value: Ticket Id



  5. Add the script below and click Save.

    ticket_resp = zoho.desk.getRecordById("<OrgId>","tickets",ticket_id);
    info "ticket_resp: " + ticket_resp;
    description = ticket_resp.get("subject");
    customer_email = ticket_resp.get("email");
    search_resp = invokeurl
    [
     type :GET
     connection:"fsmconnection"
    ];
    info "search_resp: " + search_resp;
    if(search_resp == "" || search_resp == null)
    {
     desk_contact_search_resp = zoho.desk.searchRecords("<OrgId>","Contacts",{"email":customer_email});
     desk_contact_search_data = desk_contact_search_resp.get("data").toMap();
     contact_create_Map = Map();
     contact_create_Map.put("Salutation","Mr.");
     contact_create_Map.put("First_Name",desk_contact_search_data.get("firstName"));
     contact_create_Map.put("Last_Name",desk_contact_search_data.get("lastName"));
     contact_create_Map.put("Email",desk_contact_search_data.get("email"));
     contact_create_Map.put("Phone",desk_contact_search_data.get("phone"));
     contact_create_Map.put("Mobile",desk_contact_search_data.get("mobile"));
     contact_Service_Address_Map = Map();
     contact_Service_Address_Map.put("Address_Name",desk_contact_search_data.get("lastName") + " Shipping Address");
     contact_Service_Address_Map.put("Street_1",desk_contact_search_data.get("street"));
     contact_Service_Address_Map.put("City",desk_contact_search_data.get("city"));
     contact_Service_Address_Map.put("State",desk_contact_search_data.get("state"));
     contact_Service_Address_Map.put("Zip_Code",desk_contact_search_data.get("zip"));
     contact_Service_Address_Map.put("Country",desk_contact_search_data.get("country"));
     contact_Billing_Address_Map = Map();
     contact_Billing_Address_Map.put("Address_Name",desk_contact_search_data.get("lastName") + " Billing Address");
     contact_Billing_Address_Map.put("Street_1",desk_contact_search_data.get("street"));
     contact_Billing_Address_Map.put("City",desk_contact_search_data.get("city"));
     contact_Billing_Address_Map.put("State",desk_contact_search_data.get("state"));
     contact_Billing_Address_Map.put("Zip_Code",desk_contact_search_data.get("zip"));
     contact_Billing_Address_Map.put("Country",desk_contact_search_data.get("country"));
     contact_create_Map.put("Service_Address",contact_Service_Address_Map);
     contact_create_Map.put("Billing_Address",contact_Billing_Address_Map);
     cr_resp = zoho.fsm.createRecord("Contacts",contact_create_Map);
     customer_id = cr_resp.get("data").toMap().get("Contacts").toMap().get("id");
    }
    else
    {
     customer_id = search_resp.get("data").toMap().get("id");
    }
    customer_resp = zoho.fsm.getRecordById("Contacts",customer_id);
    customer_data = customer_resp.get("data").toMap();
    Billing_Address_Map = customer_data.get("Billing_Address").toMap();
    if(Billing_Address_Map != null)
    {
     billing_Address_map = Map();
     billing_Address_map.put("id",Billing_Address_Map.get("id"));
     billing_Address_map.put("Billing_Street_1",Billing_Address_Map.get("Street_1"));
     billing_Address_map.put("Billing_Street_2",Billing_Address_Map.get("Street_2"));
     billing_Address_map.put("Billing_City",Billing_Address_Map.get("City"));
     billing_Address_map.put("Billing_State",Billing_Address_Map.get("State"));
     billing_Address_map.put("Billing_Country",Billing_Address_Map.get("Country"));
     billing_Address_map.put("Billing_Zip_Code",Billing_Address_Map.get("Zip_Code"));
    }
    Service_Address_Map = customer_data.get("Service_Address").toMap();
    if(Service_Address_Map != null)
    {
     service_Address_map = Map();
     service_Address_map.put("id",Service_Address_Map.get("id"));
     service_Address_map.put("Service_Street_1",Service_Address_Map.get("Street_1"));
     service_Address_map.put("Service_Street_2",Service_Address_Map.get("Street_2"));
     service_Address_map.put("Service_City",Service_Address_Map.get("City"));
     service_Address_map.put("Service_State",Service_Address_Map.get("State"));
     service_Address_map.put("Service_Country",Service_Address_Map.get("Country"));
     service_Address_map.put("Service_Zip_Code",Service_Address_Map.get("Zip_Code"));
    }

    terrResp = zoho.fsm.getRecords("Territories");
    terrId = terrResp.get("data").toMap().get("id");

    createMap = Map();
    createMap.put("Summary",description);
    createMap.put("Contact",customer_id);
    createMap.put("Priority","Medium");
    createMap.put("Billing_Address",billing_Address_map);
    createMap.put("Service_Address",service_Address_map);
    createMap.put("Territory", terrId);
    response = zoho.fsm.createRecord("Requests",createMap);
    new_rec_id = response.get("data").toMap().get("Requests").toMap().get("id");
    up_map = Map();
    up_map.put("<custom_field_api_name>",ticket_id.toString());
    up_resp_res = zoho.fsm.updateRecord("Requests",new_rec_id,up_map);
    info up_resp_res;
  1. In the above custom function, replace <OrgId> with the actual value. You can find the OrgId at Setup > Developer Space > API.



  2. Replace <custom_field_api_name> with the Api name of the custom field.

Step 4: Create a workflow rule

Create a workflow rule in Zoho Desk to create a request in FSM when the status of a Zoho Desk ticket changes to Moved to FSM.
  1. Navigate to Setup > Automation > Workflows and click Create Rule.



  2. In the New Workflow page, enter the following details and click Next.
    1. Module: Tickets
    2. Rule Name: CreateRequestFromTicket



  3. For Execute on, select Field Update and select the field Status and click Next.



  4. For Criteria, select Status is CLOSED Status includes, Moved to FSM, Closed and click Next.



  5. For Actions, select Custom Functions and click Existing.



  6. In the Associate Existing Custom Functions, select CreateRequestInFSM.



  7. Click Save.

Step 5: Create a custom field

Create a custom field Desk Ticket ID of type single line in the Requests module. This field will be used to store the ID of the Zoho Desk ticket from which the request was created.  Use the Api name in the custom function.


Testing the use case

Change the status of ticket to Moved to FSM.



A Request will be created in FSM.