Function Inputs in Report Filter
Is it possible to pass a field into a function in a report filter? I have a use case where employees are broken out into different branches based on geographical region, however there are certain regional managers that reside over multiple branches. I'd like to filter a Deals report where account managers can only see their own deals, servicing managers can see all deals in the branch, and regional managers can see all deals in each branch they manage.
I have created separate users and branch forms with bi-directional multi-select lookups. In the Deals form, I have a Branch lookup dropdown field that I will use to match against the function. I am then using deluge to add the Branch based on the account manager's assigned branch. I created a deluge function that takes in a Branch ID, gets all branches for the logged in user, and returns the Branch ID if one matches (otherwise returns 0). This way if I were able to pass the Deal's Branch lookup field in the report filter into the function, I'd be able to filter for one or more branches.
Deal report filter:
- Blueprint_Stage == "Account Manager Review" && Branch.ID == thisapp.UserFunctions.getMatchingUserBranch(input.Branch)
- I tried setting the function argument as Branch.ID, but I got errors when loading the report. By putting in Branch, it auto-corrects it to input.Branch when I save the filter.
UserFunctions.getMatchingUserBranch definition:
- int UserFunctions.getMatchingUserBranch(int BranchID)
- {
- branchList = Users[Zoho_User == zoho.loginuser].Branch;
- for each userBranch in branchList
- {
- if(userBranch == BranchID)
- {
- return BranchID;
- }
- }
- return 0;
- }
In the report, I'm not getting any errors, but I'm also not getting any records that match the criteria. I know this is a complex case. Please let me know if I need to further clarify anything or if there is another solution entirely to this problem!