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;

    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









                                            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

                                                                                                              • How to filter a report embedded in a page with multiple values

                                                                                                                When embedding a report in a page, Zoho Creator provides a built-in filter option for direct report filtering. However, for dynamic filtering with multiple values, you can pass the values to the page variable and use it to filter the report. This ...
                                                                                                              • 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. As ...
                                                                                                              • Dynamically Filter Lookup Options Based on Another Lookup Field's Selection

                                                                                                                Requirement Automate the creation of portal user accounts based on the email entered in the Zoho Creator form. Use Case Consider an IT asset management application on which an organization relies to register and monitor assets assigned to employees. ...
                                                                                                              • Showing only logged in user's records in a filtered report

                                                                                                                Requirement   Display only the relevant records for the logged in user, based on the customer email, to ensure the security and privacy of the data from other users in the application. Use Case   An order management application has the Order form ...
                                                                                                                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