Hi,
Run
a SSRS Report from Form via Controller Class with Query Parameters in AX D365
1. Create
a Report and query with WorkId parameter.
2. Create
Controller class as below (refers the report and links report query parameter WorkId)
and make sure Query table and class table matches)
///
<summary>
/// The <c> Test_WHSWorkController
</c> class is the controller class for the
/// <c>TestWorkReport</c> report.
///
</summary>
class Test_WHSWorkController
extends SrsReportRunController
{
/// <summary>
/// Sets the report query ranges based on
caller.
/// </summary>
protected void
prePromptModifyContract()
{
this.setRanges(this.parmReportContract().parmQueryContracts().lookup(this.getFirstQueryContractKey()));
}
/// <summary>
/// Sets the report
query ranges based on caller.
/// </summary>
/// <param
name="_query">
/// The hold the
<c>Query</c> object of the report.
/// </param>
public void
setRanges(Query _query)
{
QueryBuildRange queryBuildRange;
QueryBuildDataSource queryBuildDataSource;
FormDataSource workTableDS;
WHSWorkTable workTable;
str range;
if
(this.parmArgs()
&&
this.parmArgs().caller()
&& this.parmArgs().dataset()
== tableNum(WHSWorkTable))
{
workTableDS = FormDataUtil::getFormDataSource(this.parmArgs().record());
if
(_query && workTableDS)
{
//
build range
for
(workTable = workTableDS.getFirst(true)
? workTableDS.getFirst(true) : workTableDS.cursor();
workTable;
workTable =
workTableDS.getNext())
{
range = range == ''
? workTable.WorkId : range + ',' + workTable.WorkId;
}
if
(range)
{
queryBuildDataSource =
_query.dataSourceTable(tableNum(WHSWorkLine));
//
check for QueryBuildDataSource
if
(queryBuildDataSource)
{
//
find the range, if it's not found add it
queryBuildRange =
queryBuildDataSource.findRange(fieldNum(WHSWorkLine,
WorkId));
if
(!queryBuildRange)
{
queryBuildRange =
queryBuildDataSource.addRange(fieldNum(WHSWorkLine,
WorkId));
}
queryBuildRange.value(range);
}
}
}
}
}
public static void
main(Args _args)
{
Test_WHSWorkController controller = new Test_WHSWorkController();
controller.parmReportName(ssrsReportStr(TestWorkReport,
Report));
controller.parmArgs(_args);
controller.startOperation();
}
}
3. Create
Output menu item and refer Controller class.
4. Add
this Output menu item in Work form (WHSWorkTable). Make sure auto declaration
and needs record properties set Yes
5. Selected
Work or works are printed in newly created work report. (Parameter Screen shot)
Comments
Post a Comment