Class ReportBuildFunction
Configures the report before it is executed: populates parameter lists, sets defaults, and controls parameter visibility.
Implements
Inherited Members
Namespace: PayrollEngine.Client.Scripting.Function
Assembly: PayrollEngine.Client.Scripting.dll
Syntax
public class ReportBuildFunction : ReportFunction, IDisposable
Remarks
This function runs when the user opens a report to prepare the parameter form. It is called every time the form is refreshed. Use it to dynamically populate drop-down lists, pre-select defaults, and show or hide parameters based on other parameter values or the user context.
Key capabilities:
- Set a parameter value: SetParameter(string, string) / SetParameter<T>(string, T).
- Show/hide parameters: ShowParameter(params string[]) / HideParameter(params string[]). Use SetParameterReadOnly(string, bool) to make a single-option parameter non-editable.
- Populate a list: ExecuteInputListQuery(string, Dictionary<string, string>, string, Func<DataRow, object>, Func<DataRow, string>, Func<List<object>, object>) queries the API and
sets the
ListandListValuesparameter attributes in one call. BuildInputList(DataTable, string, Func<DataRow, object>, Func<DataRow, string>, Func<List<object>, object>) does the same from an already-fetched DataTable. - Mark as invalid: BuildInvalid() blocks report execution (e.g. when a required lookup is missing).
Return value: Return null to indicate a successful build and
allow the user to edit parameters. Return false to mark the report as not buildable.
For queries, data assembly, and result post-processing see ReportStartFunction and ReportEndFunction.
Examples
// Resolve the payroll id from the PayrollId parameter, then build an employee list
var payrollId = ResolveParameterPayrollId() ?? 0;
ExecuteInputListQuery(
"QueryEmployees",
new QueryParameters()
.ActiveStatus()
.Parameter("TenantId", TenantId)
.Parameter("PayrollId", payrollId),
"EmployeeId",
row => row.GetValue<int>("EmployeeId"),
row => row.GetValue<string>("LastName") + ", " + row.GetValue<string>("FirstName"));
// Hide a parameter when only one payroll exists
var payrollId = ResolveParameterPayrollId();
if (payrollId.HasValue)
HideParameter("PayrollId");
Constructors
View SourceReportBuildFunction(object)
Initializes a new instance with the function runtime
Declaration
public ReportBuildFunction(object runtime)
Parameters
| Type | Name | Description |
|---|---|---|
| object | runtime | The runtime |
ReportBuildFunction(string)
New function instance without runtime (scripting development)
Declaration
public ReportBuildFunction(string sourceFileName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sourceFileName | The name of the source file |
Methods
View SourceBuild()
Entry point for the runtime
Declaration
public bool? Build()
Returns
| Type | Description |
|---|---|
| bool? |
Remarks
Internal usage only, do not call this method
BuildInputList(DataTable, string, Func<DataRow, object>, Func<DataRow, string>, Func<List<object>, object>)
Build report parameter input list
Declaration
public List<object> BuildInputList(DataTable table, string reportParameter, Func<DataRow, object> identifierFunc, Func<DataRow, string> displayFunc = null, Func<List<object>, object> selectFunc = null)
Parameters
| Type | Name | Description |
|---|---|---|
| DataTable | table | List data table |
| string | reportParameter | Report parameter name |
| Func<DataRow, object> | identifierFunc | Identifier function |
| Func<DataRow, string> | displayFunc | Display function: return null to use the identifier for display |
| Func<List<object>, object> | selectFunc | Selection function: return the selected identifier or null |
Returns
| Type | Description |
|---|---|
| List<object> | List of identifiers, selected by the identifier function |
Remarks
Use the query order-by for sorting
BuildInvalid()
Set report build to invalid
Declaration
public void BuildInvalid()
BuildValid()
Set report build to valid
Declaration
public void BuildValid()
BuildValidity(bool)
Set report build validity
Declaration
public void BuildValidity(bool valid)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | valid | Build validity |
ExecuteInputListQuery(string, Dictionary<string, string>, string, Func<DataRow, object>, Func<DataRow, string>, Func<List<object>, object>)
Build report parameter input list based on query
Declaration
public List<object> ExecuteInputListQuery(string queryMethod, Dictionary<string, string> queryParameters, string reportParameter, Func<DataRow, object> identifierFunc, Func<DataRow, string> displayFunc = null, Func<List<object>, object> selectFunc = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | queryMethod | Query method name |
| Dictionary<string, string> | queryParameters | Query parameters |
| string | reportParameter | Report parameter name |
| Func<DataRow, object> | identifierFunc | Identifier function |
| Func<DataRow, string> | displayFunc | Display function: return null to use the identifier for display |
| Func<List<object>, object> | selectFunc | Selection function: return the selected identifier or null |
Returns
| Type | Description |
|---|---|
| List<object> | List of identifiers, selected by the identifier function |
Remarks
Use the query order-by for sorting
HideParameter(params string[])
Hide report parameter
Declaration
public void HideParameter(params string[] parameterNames)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | parameterNames | The parameter name |
SetParameter(string, string)
Set report parameter value
Declaration
public void SetParameter(string parameterName, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | parameterName | The parameter name |
| string | value | The parameter value as JSON |
SetParameterHidden(string, bool)
Set the report parameter hidden state
Declaration
public void SetParameterHidden(string parameterName, bool hidden)
Parameters
| Type | Name | Description |
|---|---|---|
| string | parameterName | The parameter name |
| bool | hidden | The hidden state |
SetParameterReadOnly(string, bool)
Set the report parameter read-only state
Declaration
public void SetParameterReadOnly(string parameterName, bool readOnly)
Parameters
| Type | Name | Description |
|---|---|---|
| string | parameterName | The parameter name |
| bool | readOnly | The read-only state |
SetParameter<T>(string, T)
Set report parameter typed value
Declaration
public void SetParameter<T>(string parameterName, T value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | parameterName | The parameter name |
| T | value | The default value |
Type Parameters
| Name | Description |
|---|---|
| T |
ShowParameter(params string[])
Show report parameters
Declaration
public void ShowParameter(params string[] parameterNames)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | parameterNames | The parameter names |