Hi All,
Really often you may want to have some default values for report parameters, that may depend on environment. For example different default warehouse depend on branch where are you working now. Or different warehouse depend on current employee.
But unfortunately it is not out of the box functionality in Acumatica.
Luckily, using powerful Acumatica Customization engine it is quite easy to do. Let me share with you a way to archive it.
Scenario: lets assume that we want to have different default warehouse on Inventory Valuation report based on different branch that is selected as current.
We will do this task in 3 steps:
- Adding custom field to link branch and warehouse
- Create a class that can evaluate required warehouse by currently selected branch
- Provide default parameter in report
Step 1: Adding custom field to Branch screen.
To store association between Branch and Warehouse we need to add new field there. To do this, please follow the instruction and image attached:
- Create a customization project
- Open Branches screen
- Select tab with branch configurations
- Create new custom field
- Adjust attributes of custom field like here:
- [Site()]
- Publish customization
- Refresh page
- Create a control on the page from custom field. Make sure that you have selector
- Publish customization once again
Customization extension is here:
public class BAccountExt : PXCacheExtension<PX.Objects.CR.BAccount> { #region UsrDefaultWarehouse [Site()] public virtual int? UsrDefaultWarehouse { get; set; } public abstract class usrDefaultWarehouse : IBqlField { } #endregion }
Step 2: Creating a new virtual DAC for providing default values to report.
We need to have a object that will evaluate a warehouse based on currently selected branch. So here we need to create an data access class with auto-calculated field:
public class ReportsDefault : IBqlTable { #region UsrDefaultWarehouse [Site()] [PXDefault(typeof(Search2<BAccountExt.usrDefaultWarehouse, InnerJoin<Branch, On<Branch.bAccountID, Equal<BAccount.bAccountID>>>, Where<Branch.branchID, Equal<Current<AccessInfo.branchID>>>>))] public virtual int? UsrDefaultWarehouse { get; set; } public abstract class usrDefaultWarehouse : IBqlField { } #endregion }
Do not forget to publish project after adding an new DAC.
The key point here is AccessInfo class, that provides us access to current environment variables. Here you can see list of all usable variables:
- BaseCuryID – ID of the base currency implemented in current tenant
- BranchID – currently selected branch.
- BusinessDate – business that that was selected on top of Acumatica main page
- ScreenID – ID of current screen
- UserID – ID of currently logged it user.
For calculation your defaults you can use any of these fields. Employee usually is linked to user, so you can evaluate current employee by user name.
Step 3: Default value for report parameter
Lets open required report and select warehouse parameter on Build Schema form.
To provide default value we just need to link the parameter and the new DAC. Report.GetDefExt will call DAC business logic and will automatically evaluate value accordingly to formula specified in step 2.
=Report.GetDefExt(‘EmployeeDefault.UsrDefaultWarehouse’)
That is all. Now you can test it!
Code snippet:
Have a nice development!