Filter report using dynamic values from a function

Filter report using dynamic values from a function

Requirement

When a user accesses a report, data is filtered based on the logged-in user's role so that only the required details are visible to the user.

Use Case

An employee management system has two forms, Department and Employees. The Department form has the list of various departments and the Employees form holds the details of employees. Multiple employees can belong to a department. In this application, when the head of a department logs in to the application, the employees in their department alone are listed for their perusal.

Steps to follow

1. Create the forms with the following details:

Form

Form Link Name

Field Type

Field Name

Field Link Name

Department

Department

Single Line

Department Name

Department_Name

Employees

Employees

Name

Name

Name

Lookup (Department)

Department

Department

Email

Official Email

Official_Email

Phone

Phone

Phone_Number


The Official Email field holds the email ID the employee uses to log in to the employee management application.
 
2) Let us now create a function to find the department of the current logged-in user. Create a function named getDepartment and select the return type int.
 
(Lookups are referenced based on the record link IDs of the relevant records in their base forms, so the return type of this function is int (number). This function is going to search employee reports to find employees based on this lookup value.)
 
3) Add the below code in the ensuing Deluge editor:
  1. int getDepartment()
  2. {
  3. //Fetch the department record based on login user email ID
  4. employee = Employees[Official_Email = zoho.loginuserid];
  5. return employee.Department;
  6. }
This function searches the employee records from the All Employees report based on the logged-in user's email ID. From the Employee record, the corresponding Department record's ID value is returned.
 
4) Add a filter to the All Employees report using the getDepartment function to match the ID in the Department form:
 


See how it works


Points to note

  • The Department field in the Employee form can be created as a picklist. In this case, the getDepartment function can return the Department value as a string directly and the filter can also be done. (Since integer comparison would be more optimal than string comparison, lookup was used in this example.) The sample code could be:
  1. string getDepartment()
  2. {
  3. return Employee [ Official_Email == zoho.loginuserid ].Department;

    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





                        Still can't find what you're looking for?

                        Write to us:  support@zohoforms.com


                              




                            

                            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 SalesIQ Resources



                                                      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

                                                                                          • Statistical values on a report based on numerical fields

                                                                                            Requirement Display the common statistical results on the reports for the numerical fields in a form, to help in identifying trends and decision-making process. Use Case In any sales-based business, crunching numbers is a big task. An order ...
                                                                                          • Building an employee dashboard

                                                                                            Requirement   Create an employee dashboard with buttons that will help the employees to check in and out, find the total number of logged-in hours and apply for leave. Use Case   An Employee Management application has a dashboard for their employees. ...
                                                                                          • Create a search functionality to dynamically filter a report

                                                                                            Requirement Create a search functionality for users to find specific records based on their search queries. Use Case An order management app is used by a business to store its customer details, and by billing agents to order products. There are three ...
                                                                                          • Update a form using custom action (from another form's report)

                                                                                            Requirement   Update a form using a custom action configured in another form's report. Use Case In an engineering college student management application, a student may withdraw at any time of the academic year. Whenever a student applies for ...
                                                                                          • Auto-calculating values on a subform's field

                                                                                            Requirement Perform statistical operations on the numerical fields in subforms for analysis. Use Case  In an order management application, there are two forms, Order and Product. The Product form lists all the products in the inventory and the Order ...
                                                                                          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