Zoho FSM | Create Work Orders in Bulk using Zoho Sheets

Create Work Orders in Bulk using Zoho Sheets

Use case: Using Zoho Sheets, import/create multiple work orders at once. Here, taxes have not been considered.
 
Follow the steps below to implement this use case:
Step 1: Prepare a sheet with the work order values
Step 2: Create a custom function

Step 1: Prepare a sheet with the work order values

Prepare a sheet with the values you want to create the work orders with. Refer to the attached sheet to know the format in which you need to add the values in the sheet.
 
NoteBecause of Zoho FSM API limits, at a time, include only up to 100 entries in the sheet.

Step 2: Create a custom function

In Zoho FSM, create a function to generate work orders from the sheet.
  1. Navigate to Setup > Automation > Actions. Go to the Deluge Functions tab and click Create Function.
  2. Enter the following details and click Save:
    1. Function Name: CreateBulkWOs
    2. Module: Work Orders
    3. In the Deluge Script Editor, enter the following script:

      bodyMap = Map();
      headerMap = Map();
      headerMap.put("Authorization","Zoho-oauthtoken 1000.XXXXX");
      response = postUrl(url,bodyMap,headerMap);
      response_list = response.get("records").toList();
      for each  response_map in response_list
      {
      createMap = Map();
      billing_id = response_map.get("Billing_Address");
      service_id = response_map.get("Service_Address");
      service_line_items = response_map.get("Service_Line_Items");
      s = 1;
      Service_items_list = list();
      for each  service in service_line_items
      {
      Service_items_ma = Map();
      Service_items_ma.put("Service",service.get("Service"));
      Service_items_ma.put("Quantity",service.get("Quantity"));
      Service_items_ma.put("Sequence",s);
      s = s + 1;
      Service_items_list.add(Service_items_ma);
      }
      p = 1;
      part_line_list = list();
      part_line_items = response_map.get("part_line_items");
      if(!part_line_items.isNull() && !part_line_items.isEmpty())
      {
      for each  parts in part_line_items
      {
      Part_line_resp = Map();
      Part_line_resp.put("Part",parts.get("parts"));
      Part_line_resp.put("Quantity",parts.get("Quantity"));
      Part_line_resp.put("Sequence",p);
      p = p + 1;
      part_line_list.add(Part_line_resp);
      }
      }
      data = Map();
      data.put("Part_Line_Items",part_line_list);
      if(!Service_items_list.isEmpty() && Service_items_list != null)
      {
      for each  service in Service_items_list
      {
      service.putAll(data);
      break;
      }
      }
      // info service_line_items ;
      createMap.put("Territory",response_map.get("Territory"));
      createMap.put("Summary",response_map.get("Summary"));
      createMap.put("Contact",response_map.get("Contact"));
      createMap.put("Company",response_map.get("Company"));
      createMap.put("Type",response_map.get("Type"));
      createMap.put("Email",response_map.get("Email"));
      createMap.put("Phone",response_map.get("Phone"));
      createMap.put("Mobile",response_map.get("Mobile"));
      createMap.put("Due_Date",response_map.get("Appointment Date"));
      createMap.put("Billing_Address",{"id":billing_id});
      createMap.put("Service_Address",{"id":service_id});
      createMap.put("Service_Line_Items",Service_items_list);
      info createMap;
      create_response = zoho.fsm.createRecord("Work_Orders",createMap);
      info create_response;
      }
In the above function, the Zoho Sheet API used to create work orders from the Zoho Sheet values is Fetch records from worksheet.
 
Following are the details on how to fetch the parameter values for this API.
  1. <resource_id>
    The resource_id is the alphanumeric value in the sheet's URL. Refer to the screenshot below.



  2. <worksheet_name>
    Go to the List all worksheets API page. Select your Spreadsheet Name and click Submit. You can find the worksheet_name in the Response. Refer to the screenshot below.



    Here the worksheet_name value is BulkWOs.

  3. <worksheet_id>

    Go to the List all worksheets API page. Select your Spreadsheet Name and click Submit. You can find the worksheet_id in the Response. Refer to the screenshot below.



    Here the value of worksheet_id is 0#.
To fetch the Zoho-oauthtoken:
  1. Click Generate Access Token.



  2. The Zoho-oauthtoken value will be displayed as shown in the screenshot below.

Testing the usecase

  1. Navigate to Setup > Automation > Actions. Go to the Deluge Functions tab and click on the function CreateBulkWOs.
  2. In the Deluge Script Editor, click Save & Execute.
  3. In the Execute Function pop-up, enter a Request record ID or click Click here to get the list to obtain the list of available Request IDs.
  4. Select a Request ID and click Execute.

The created work orders can be seen in the Work Orders List page.