Zoho FSM | Create a Work Order in Zoho FSM whenever a Subscription is created or renewed

Create a Work Order in Zoho FSM whenever a Subscription is created or renewed

Use case: Whenever a subscription is created or renewed in Zoho Billing, create a Work Order in Zoho FSM.
 
Step 1: Add a service named ForZBilling
Step 2: Create a connection for Zoho FSM in Zoho Billing
Step 3: Create a custom function in Zoho Billing

Step 1: Add a service named ForZBilling

In Zoho FSM, create a service called ForZBilling. Use this service in the work order that you create when a subscription is created or renewed in Zoho Billing.
 

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

To create a connection for Zoho FSM that can be used in Zoho Billing for invoking the Zoho FSM APIs, do the following:
  1. Log in to Zoho Billing.
  2. Navigate to Settings > Developer Data > Connections and click New Connection.



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



  4. Do the following and click Create And Connect:
    1. Connection Name: Zoho FSM. The Connection Link Name will be automatically populated.
    2. Disable Use Credentials Of Login User. If this is disabled, the connection will utilize the credentials of the connection owner.
    3. Select the Scope ZohoFSM.modules.all.
  5. Click Connect.



  6. Click Accept.

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

Step 3: Create a custom function in Zoho Billing 

Add a custom function in Zoho Billing to create a work order in Zoho FSM whenever a subscription is created or renewed in Zoho Billing.
  1. Navigate to Settings > Automation > Custom Functions and click New Custom Function.



  2. In the New Custom Function page, enter the following details:
    1. Name: CreateWOInZFSM
    2. Module: Subscriptions
    3. Select New Subscription, and Subscription Renewal under Predefined Events > Immediate Events.



  3. In the Deluge Script Editor, enter the following script and click Save:


    custEmail = subscriptions.get("customer").toMap().get("email");
    response = zoho.fsm.searchRecordsByField("Contacts","Email",custEmail,Map(),"zohofsm");
    subscription_number = subscriptions.get("subscription_number");
    name = subscriptions.get("name");
    summary = subscription_number + ":" + name;
    response = response.get("data").toMap();
    tax = response.get("Tax").toMap();
    //info tax; 
    custId = response.get("id");
    companyMap = response.get("Company");
    if(companyMap == null)
    {
    compId = "";
    }
    else
    {
    compId = companyMap.toMap().get("id");
    }
    serviceAddressMap = response.get("Service_Address");
    if(serviceAddressMap == null)
    {
    serviceAddressId = "";
    }
    else
    {
    serviceAddressId = serviceAddressMap.toMap().get("id");
    }
    billingAddressMap = response.get("Billing_Address");
    if(billingAddressMap == null)
    {
    billingAddressId = "";
    }
    else
    {
    billingAddressId = billingAddressMap.get("id");
    }
    Service_Address_Map = Map();
    Billing_Address_Map = Map();
    Service_Address_Map.put("id",serviceAddressId);
    Billing_Address_Map.put("id",billingAddressId);
    serviceList = List();
    response1 = zoho.fsm.searchRecordsByField("Service_And_Parts","Name","ForZBilling",Map(),"zohofsm");
    //info response1;
    if(!response1.isNull() && !response1.isEmpty())
    {
    service = response1.get("data").toMap();
    serviceMap = Map();
    serviceMap.put("Quantity",1);
    serviceMap.put("Sequence",1);
    serviceMap.put("List_Price",service.get("Unit_Price"));
    serviceMap.put("Service",service.get("id"));
    serviceMap.put("Contact",custId);
    serviceMap.put("Tax",tax);
    serviceList.add(serviceMap);
    }
    terrResp = zoho.fsm.getRecords("Territories");
    terrId = terrResp.get("data").toMap().get("id");
    createWOMap = Map();
    createWOMap.put("Summary",summary);
    createWOMap.put("Priority","Medium");
    createWOMap.put("Type","Service");
    createWOMap.put("Email",custEmail);
    createWOMap.put("Contact",custId);
    createWOMap.put("Company",compId);
    createWOMap.put("Territory",terrId);
    createWOMap.put("Service_Address",Service_Address_Map);
    createWOMap.put("Billing_Address",Billing_Address_Map);
    createWOMap.put("Service_Line_Items",serviceList);
    info "createWOMap: " + createWOMap;
    woResp = zoho.fsm.createRecord("Work_Orders",createWOMap);
    info woResp;

Testing the use case 

Following are the steps to test the use case discussed:
  1. Select Subscriptions in the left menu and click on + New Subscription.



  2. Select a Customer, add a Plan and click Continue. Select the checkbox Collect payment offline.
    Ensure that the contact you choose is present in Zoho FSM. A Service Address, Billing Address, and Email should be present for the contact.



  3. Click Create.


A work order is created in Zoho FSM.