Zoho FSM | Create an Estimate in Zoho Invoice from a Work Order in Zoho FSM

Create an Estimate in Zoho Invoice from a Work Order in Zoho FSM

Use case: Whenever a Work Order is created in Zoho FSM, create an Estimate for it in Zoho Invoice.
 
Follow the steps below to implement this use case:
Step 1: Create a custom function
Step 2: Create a workflow rule

Step 1: Create a custom function  

Create a custom function in Zoho FSM that will generate an estimate in Zoho Invoice from a work order in Zoho FSM.
  1. Navigate to Setup > Automation > Functions and click Create Function.
  2. Enter the following details and click Save:
    1. Function Name: CreateEstimateFromWO
    2. Module: Work Order
    3. In the Deluge Script Editor, enter the following script:

      contact_id = work_order.get("Contact").toMap().get("id");
      contact_resp = zoho.fsm.getRecordById("Contacts",contact_id);
      invoice_contact_id = contact_resp.get("data").toMap().get("ZBilling_Id");
      listVar = List();
      Service_Line_Item_List = work_order.get("Service_Line_Items").toList();
      for each  line in Service_Line_Item_List
      {
       line_map = line.toMap();
       line_name = line_map.get("Service").toMap().get("name");
       line_id = line_map.get("Service").toMap().get("id");
       line_resp = zoho.fsm.getRecordById("Service_And_Parts",line_id);
       invoice_line_id = line_resp.get("data").toMap().get("ZBilling_Id");
       mapVar = Map();
       mapVar.put("item_id",invoice_line_id);
       mapVar.put("name",line_name);
       mapVar.put("rate",line_map.get("List_Price"));
       mapVar.put("quantity",line_map.get("Quantity"));
       listVar.add(mapVar);
      }
      Part_Line_Item_List = work_order.get("Part_Line_Items").toList();
      for each  line in Part_Line_Item_List
      {
       line_map = line.toMap();
       line_name = line_map.get("Part").toMap().get("name");
       line_id = line_map.get("Part").toMap().get("id");
       line_resp = zoho.fsm.getRecordById("Service_And_Parts",line_id);
       invoice_line_id = line_resp.get("data").toMap().get("ZBilling_Id");
       mapVar = Map();
       mapVar.put("item_id",invoice_line_id);
       mapVar.put("name",line_name);
       mapVar.put("rate",line_map.get("List_Price"));
       mapVar.put("quantity",line_map.get("Quantity"));
       listVar.add(mapVar);
      }
      values = Map();
      values.put("customer_id",invoice_contact_id);
      values.put("line_items",listVar);
      response = zoho.invoice.create("Estimates","<orgId>",values);
      info response;
Replace <orgId> with the actual value. To obtain the Organization ID, in Zoho Invoice, click the organization name at the top right corner and copy the Invoice Organization ID linked to your Zoho FSM account.


 
Additionally ensure that the status of the internal connections for Zoho FSM, and Zoho Invoice integration tasks are Connected. The green dot [] indicates that the connection is Connected.
 

Step 2: Create a workflow rule  

Create a workflow rule in Zoho FSM to automatically generate an estimate in Zoho Invoice 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: CreateEstimateForWO
    3. Description: Generate an Estimate in Zoho Invoice when a Work Order is created in Zoho FSM.



  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 usecase  

Create a Work Order in Zoho FSM.
 

 
An estimate will be created in Zoho Invoice.