I have a Common function written in Acumatica and we use that on various Acumatica screen, we would like to use this function in report designer so we could print the value.
Example: CheckBday() If we pass a customer code it shld check this customer birthday field and if it's today then it returns "Happy Birthday"
Is it possible to call this common function in report designer to process? If so how can this be achieved in the report designer, any insight will be helpful.
You can use extended functions on Report Designer by using User Define Functions(UDF).
You could:
- Create a new AddOn project called ReportUDF. Add a new class file called UtilFunctions.cs.
Add public function YOURFUNCTION:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PX.Objects.AP;
namespace ReportUDF
{
public class UtilFunctions
{
public string YOURFUNCTION(string PARAM)
{
try
{
//function code
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}
Parameters and Their Data Types:
Methods in your class should always contain parameters of type string and always return a value of type string. The best way to handle the parameters and return parameters are by declaring them of the Object type. However, you will need to convert these parameters to the appropriate data types before consuming or using them to ensure proper operation of your methods.
Compile this Add-On Project. Upon successful compile, ensure the assembly (ReportUDF.dll) is placed in the Bin folder of Acumatica website.
Wire up this new assembly in ReportLauncher.aspx.cs as described below:
- Open ReportLauncher.aspx.cs file (Website Folder > Frames) in Visual Studio.
Add the following lines of code to the bottom of the static constructor Pages_ReportLauncer:
Type DemoReportFunctionsType =
System.Web.Compilation.BuildManager.GetType("ReportUDF.UtilFunctions", false);
if(DemoReportFunctionsType != null)
{
ExpressionContext.RegisterExternalObject("ReportUDF",Activator.CreateInstance(DemoReportFunctionsType));
}
Open your form report in Report Designer and add TextBox control with following expression as shown below:
= ReportUDF.YOURFUNCTION([DAC.UsrSomeField])
Observation: UDFs do not show up in the Expression Editor.
- Save and run the report.
Observation: Customizing ReportLauncher.aspx.cs is not a standard practice and changes during upgrades should be reapplied. You can always compile these changes as part of a customization package; however, you should ensure that enhancements (if any are present) to this code file are preserved during upgrades. Otherwise reports may not function as expected.
As @cbetabeta mentioned, using Reports User Defined Function(UDF)
is one of the possible approach. But maintaining customized ReportLauncher.aspx.cs
version to version would be a challenge.
Alternate possible approach for this could be via unbound DAC field having PXFormula
/PXDBScalar
/PXDBCalced
attribute. You could use custom BQL Function (derived from BqlFormulaEvaluator
) as well – You can refer out-of-box custom BQL functions available in formula sub-folder of PX.Objects
source code. Or you can refer KB article where such custom BQL function HierarchySorting
is used.