Zoho FSM | Create an Expense record for a Work Order

Create an Expense record for a Work Order

Use case: In a work order, if the user adds service line items to record expenses, then create an Expense record in Zoho Expense for an amount equivalent to the sum of all such service Line Item Amount. A service called Expense will be used for this purpose. Also, update a custom field in the work order with the ID of the Expense record created.
 

Step 1: Add a service named Expense 

In Zoho FSM, create a service called Expense. Add a Unit Price that you want to charge for your expenses. Use this service in your work order to add the expenses for your work order.
 

Step 2: Create a custom field

Create a custom field Zoho Expense Record ID of type single line in the Work Orders module. This field will be used to store the ID of the Expense record created for the work order.  Use the Api name in the custom function.


Step 3: Create a connection for Zoho Expense 

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



  2. Under Default Services, select Zoho Expense.



  3. Perform the following and click Create And Connect:
    1. Connection Name: ZExpense
      The Connection Link Name will be populated automatically.
    2. Select the Scopes ZohoExpense.FullAccess.all



  4. Click Connect.



  5. Click Accept.

In the custom function, where the Expense API is used via the invokeURL task, use this Connection Link Name.
 

 
Additionally ensure that the status of the internal connection for Zoho FSM integration task is Connected. The green dot [] indicates that the connection is Connected.
 

Step 4: Create a custom function 

Add a custom function to create an Expense record in Zoho Expense for a work order in Zoho FSM. An Expense record should be created in Zoho Expense for an Amount equivalent to the sum of all the service Line Item Amount corresponding to the line items added in the work order for the service Expense. Also update a custom field in the work order with the ID of the expense record created.
  1. Navigate to Setup > Automation > Functions and click Create Function.
  2. Enter the following details and click Save:
    1. Function Name: CreateExpenseForWO
    2. Module: Work Orders
    3. In the Deluge Script Editor, enter the following script:

      work_order_id = work_order.get("id");
      Amount = 0;
      Service_Line_Items_List = work_order.get("Service_Line_Items").toList();
      for each  Service_Line_Items in Service_Line_Items_List
      {
       Service_Line_Items_Map = Service_Line_Items.toMap();
       if(Service_Line_Items_Map.get("Service").toMap().get("name") == "Expense")
       {
        //Get Currency Id
        headers_data = Map();
        headers_data.put("X-com-zoho-expense-organizationid","<orgId>");
        response = invokeurl
        [
        type :GET
        headers:headers_data
        connection:"zexpense"
        ];
        currencyList = response.get("currencies").toList();
        for each  eachCurrencyList in currencyList
        {
        CurrencyMap = eachCurrencyList.toMap();
        if(CurrencyMap.get("currency_code") == "USD")
        {
        currency_id = CurrencyMap.get("currency_id");
        }
        }
        //Get Category Id
        headers_data_1 = Map();
        headers_data_1.put("X-com-zoho-expense-organizationid","<orgId>");
        response_1 = invokeurl
        [
        type :GET
        headers:headers_data_1
        connection:"zexpense"
        ];
        expense_categories_list = response_1.get("expense_accounts").toList();
        for each  each_expense_categories_list in expense_categories_list
        {
        expense_categories_map = each_expense_categories_list.toMap();
        //Use the Expense Category - Travel Expense
        if(expense_categories_map.get("category_name") == "Travel Expense")
        {
        category_id = expense_categories_map.get("category_id");
        }
        }
       
        Amount = Amount + Service_Line_Items_Map.get("Line_Item_Amount");
        Created_Time = Service_Line_Items_Map.get("Created_Time").toString();
        Create_Date = Created_Time.getPrefix("T");
        lineItemList = list();
        lineItemMap = Map();
        lineItemMap.put("category_id",category_id);
        lineItemMap.put("amount",Amount);
        lineItemMap.put("description","From Zoho FSM");
        lineItemList.add(lineItemMap);
        createMap = Map();
        createMap.put("currency_id",currency_id);
        createMap.put("date",Create_Date);
        createMap.put("is_reimbursable",true);
        createMap.put("line_items",lineItemList);
        headers_data_2 = Map();
        headers_data_2.put("X-com-zoho-expense-organizationid","<orgId>");
       
        response_2 = invokeurl
        [
        type :POST
        parameters:createMap.toString()
        headers:headers_data_2
        connection:"zexpense"
        content-type:"application/json"
        ];
       
        expense_id = response_2.get("expenses").toMap().get("expense_id").toString();
        updateResp = zoho.fsm.updateRecord("Work_Orders",work_order_id,{"<custom_field_Api_name>":expense_id});
       }
      }
      Note: In this custom function, the Expense Category used is Travel Expense.

  3. Replace <orgId> with the actual value. To obtain the Organization ID, in Zoho Expense, click the organization name at the top right corner and copy the Expense Organization ID.



  4. Replace <custom_field_Api_name> with the Api name of the custom field.

Step 5: Create a workflow rule 

Create a workflow rule in Zoho FSM to automatically create an Expense record in Zoho Expense for a Work Order.
  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: CreateExpenseForWO
    3. Description: Create an expense record for a work order



  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. Add a service line item with the service Expense. Enter a Quantity of your choice.
 

 
An expense record with an Amount equivalent to the Line Item Amount for the Expense service line item will be added.
 

In the work order, the ID of the expense record created will be saved to the Zoho Expense Record ID field.
 

    Access your files securely from anywhere

      Zoho CRM Training Programs

      Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

      Zoho CRM Training
        Redefine the way you work
        with Zoho Workplace

          Zoho DataPrep Personalized Demo

          If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

          Zoho CRM Training

            Create, share, and deliver

            beautiful slides from anywhere.

            Get Started Now


              Zoho Sign now offers specialized one-on-one training for both administrators and developers.

              BOOK A SESSION





                          Quick Links Workflow Automation Data Collection
                          Web Forms Enterprise Begin Data Collection
                          Interactive Forms Workplace Data Collection App
                          CRM Forms Customer Service Accessible Forms
                          Digital Forms Marketing Forms for Small Business
                          HTML Forms Education Forms for Enterprise
                          Contact Forms E-commerce Forms for any business
                          Lead Generation Forms Healthcare Forms for Startups
                          Wordpress Forms Customer onboarding Order Forms for Small Business
                          No Code Forms Construction RSVP tool for holidays
                          Free Forms Travel
                          Prefill Forms Non-Profit

                          Intake Forms Legal
                          Mobile App
                          Form Designer HR
                          Mobile Forms
                          Card Forms Food Offline Forms
                          Assign Forms Photography
                          Mobile Forms Features
                          Translate Forms Real Estate Kiosk in Mobile Forms
                          Electronic Forms

                          Notification Emails for Forms Alternatives Security & Compliance
                          Holiday Forms Google Forms alternative  GDPR
                          Form to PDF Jotform alternative HIPAA Forms
                          Email Forms
                          Encrypted Forms
                          Embeddable Forms
                          Secure Forms
                          Drag and Drop form builder


                          WCAG



                                            You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                Manage your brands on social media

                                                  Zoho Desk Resources

                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                    Zoho Marketing Automation

                                                      Zoho Sheet Resources

                                                       

                                                          Zoho Forms Resources


                                                            Secure your business
                                                            communication with Zoho Mail


                                                            Mail on the move with
                                                            Zoho Mail mobile application

                                                              Stay on top of your schedule
                                                              at all times


                                                              Carry your calendar with you
                                                              Anytime, anywhere




                                                                    Zoho Sign Resources

                                                                      Sign, Paperless!

                                                                      Sign and send business documents on the go!

                                                                      Get Started Now




                                                                              Zoho TeamInbox Resources



                                                                                      Zoho DataPrep Resources



                                                                                        Zoho DataPrep Demo

                                                                                        Get a personalized demo or POC

                                                                                        REGISTER NOW


                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now









                                                                                                              • Related Articles

                                                                                                              • Create a Work Order in FSM from a CRM Sales Order

                                                                                                                Use case: Create a work order in Zoho FSM whenever a sales order is created in Zoho CRM. Follow the steps below to implement this use case: Step 1: Create a connection for Zoho FSM in Zoho CRM Step 2: Create a workflow rule Step 3: Create a custom ...
                                                                                                              • Calculate Work Order Profit

                                                                                                                Use case: Calculate the profit earned for a work order. Profit = Grand Total of the work order - Total cost price of the work order where, Total cost price of the work order = Total cost price of the services used + Total cost price of the parts used ...
                                                                                                              • Work Orders

                                                                                                                A work order is a record created for executing a contact service request. Available in Editions: All Editions Create Work Orders Permission Required: Work Orders A Work Order can be created in one of the following ways: From Requests: Use the Convert ...
                                                                                                              • Create a Work Order in Zoho FSM from a Sales Order in Zoho Books

                                                                                                                Use case: Whenever a Sales Order is created in Zoho Books, create a Work Order for it in Zoho FSM. Follow the steps below to implement this use case: Step 1: Create a connection for Zoho FSM in Zoho Books Step 2: Create a custom function in Zoho ...
                                                                                                              • Notify Changes in Work Order Status

                                                                                                                Usecase: Notify the customer by email each time the status of the work order changes. Also, notify the customer when the payment has been done for the work order. Follow the steps below to implement this use case: Step 1: Create a custom function ...
                                                                                                                Wherever you are is as good as
                                                                                                                your workplace

                                                                                                                  Resources

                                                                                                                  Videos

                                                                                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                  eBooks

                                                                                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                  Webinars

                                                                                                                  Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                  CRM Tips

                                                                                                                  Make the most of Zoho CRM with these useful tips.



                                                                                                                    Zoho Show Resources