Zoho FSM | Create Project and Tasks in Zoho Project whenever an Invoice is generated in Zoho FSM

Create Project and Tasks in Zoho Project whenever an Invoice is generated in Zoho FSM

Usecase: Create Project and Tasks in Zoho Project whenever an Invoice is generated for a Work Order in Zoho FSM. The work order should have an associated estimate. The project in Zoho Projects will be created with the name provided in the Project Name field of the estimate. Tasks will be created within the project that correspond to the service and parts line items in the work order.
 
Follow the steps below to implement this usecase:
Step 1: Create a custom field
Step 2: Create a custom function
Step 3: Create a workflow rule

Step 1: Create a custom field  

Create a custom field Project Name of type Single Line in the Estimates module. Use the value in this field to name the project.
 

Step 2: Create a custom function  

Create a custom function in Zoho FSM to do the following in Zoho Projects:
  1. Create a project in Zoho Projects with the name provided in the Project Name field of Estimates.
  2. Create tasks within the project that correspond to the service and parts line items in the work order.
  1. Navigate to Setup > Automation > Functions and click Create Function.
  2. Enter the following details and click Save:
    1. Function Name: CreateProjectinZProject
    2. Module: Work Orders
    3. In the Deluge Script Editor, enter the following script:

      work_order_id = work_order.get("id");
      work_order_response = zoho.fsm.getRecordById("Work_Orders",work_order_id);
      estimate = work_order_response.get("data").toMap().get("Estimate");
      service_line_items = work_order_response.get("data").toMap().get("Service_Line_Items").toList();
      part_line_items = work_order_response.get("data").toMap().get("Part_Line_Items").toList();
      part_line_item_size = part_line_items.size();
      if(estimate != null)
      {
       estimate_map = estimate.toMap();
       estimate_id = estimate_map.get("id");
       estimate_resp = zoho.fsm.getRecordById("Estimates",estimate_id);
       cf_projet = estimate_resp.get("data").toMap().get("cf_projet__C");
       if(cf_projet != null)
       {
        portal_response = zoho.projects.getPortals();
        portal_name = portal_response.get("portals").toMap().get("name");
        new_project = Map();
        new_project.put("name",cf_projet);
        project_response = zoho.projects.createProject(portal_name,new_project);
        project_id = project_response.get("projects").toMap().get("id");
        for each  service_line in service_line_items
        {
         service_line_map = service_line.toMap();
         service_name = service_line_map.get("Service").toMap().get("name");
         values_map = Map();
         values_map.put("name",service_name + " (Service)");
         response = zoho.projects.create(portal_name,project_id,"tasks",values_map);
         values_map.clear();
        }
        if(part_line_item_size != 0)
        {
         for each  part_line in part_line_items
         {
          part_line_map = part_line.toMap();
          part_name = part_line_map.get("Part").toMap().get("name");
          values_map = Map();
          values_map.put("name",part_name + " (Part)");
          response = zoho.projects.create(portal_name,project_id,"tasks",values_map);
          values_map.clear();
         }
        }
       }
      } 
Note: Ensure that the status of the connection Internal_zohoprojects is Connected. The green dot [] indicates that the connection is Connected.
 

Step 3: Create a workflow rule  

Create a workflow rule in Zoho FSM to create Project and Tasks in Zoho Project whenever an Invoice is generated for a Work Order 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: Create Project and Task in Zoho Project
  3. Select the rule trigger as Edited and click Next.
  4. Select the rule criteria as Only to the Work Order matching certain conditions and add the condition Billing Status is Partially Invoiced, Invoiced. 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 from an Estimate. Provide a value in the Estimate field Project Name. A project will be created in Zoho Projects with the name provided in the Project Name field and tasks will be created within the project that correspond to the service and parts line items in the work order.