SSRS Report using Controller , Contract and RDP classes in D365
STEP 1 : Create new TEMP table
STEP 2 : Create query.
STEP 3 : Create a Contract class
[DataContractAttribute]
class SMJ_PerdiemContract
{
PerdiemStatus perdiemstatus;
[DataMemberAttribute(identifierStr(PerdiemStatus)),
SysOperationLabelAttribute ("Perdiem status"),
SysOperationHelpTextAttribute("Perdiem status"),
SysOperationDisplayOrderAttribute("1")]
public PerdiemStatus parmPerdiemStatus(PerdiemStatus _PerdiemStatus = perdiemstatus)
{
perdiemstatus = _PerdiemStatus;
return perdiemstatus;
}
}
STEP 4 : Create a DP class:
[SRSReportQueryAttribute(queryStr(SMJ_PerdiemReport)), // query
SRSReportParameterAttribute(classStr(SMJ_PerdiemContract))]// contract class
public class SMJ_PerdiemDP extends SRSReportDataProviderBase
{
SMJ_PerdiemTableTempDB perdiemTableTempDB;
PerdiemStatus perdiemStatus;
PerdiemRequestID PerdiemRequestID;
public Query buildQuery(Query _query ,PerdiemRequestID _perdiemRequestID , PerdiemStatus _perdiemStatus)
{
if(_perdiemRequestID)
_query.dataSourceTable(tableNum(PerdiemHeader),1).addRange(fieldNum(PerdiemHeader, PerdiemRequestID)).value(_perdiemRequestID);
if(_perdiemStatus)
_query.dataSourceTable(tableNum(PerdiemHeader),1).addRange(fieldNum(PerdiemHeader, PerdiemStatus)).value(queryValue(_perdiemStatus));
return _query;
}
private void getReportParameters()
{
SMJ_PerdiemContract PerdiemContract = this.parmDataContract();
perdiemStatus = PerdiemContract.parmPerdiemStatus();
}
[ SRSReportDataSetAttribute(tableStr(SMJ_PerdiemTableTempDB)) ]
public SMJ_PerdiemTableTempDB getTempData()
{
select perdiemTableTempDB;
return perdiemTableTempDB;
}
private void insertTempData(PerdiemHeader perdimeHeader, PerdiemLine perdiemLine)
{
perdiemTableTempDB.PerdiemRequestID = perdimeHeader.PerdiemRequestID;
perdiemTableTempDB.EmplNum = perdimeHeader.EmplNum;
perdiemTableTempDB.EmplName = perdimeHeader.EmplName;
perdiemTableTempDB.ApplicationDate =perdimeHeader.ApplicationDate;
perdiemTableTempDB.PerdiemStatus = perdimeHeader.PerdiemStatus;
perdiemTableTempDB.PurposeOfTravelForPerdiem = perdimeHeader.PurposeOfTravelForPerdiem;
perdiemTableTempDB.CountryRegionId = perdiemLine.CountryRegionId;
perdiemTableTempDB.CurrencyCode = perdiemLine.CurrencyCode;
perdiemTableTempDB.StartDate = perdiemLine.StartDate;
perdiemTableTempDB.EndDate = perdiemLine.EndDate;
perdiemTableTempDB.TotalNoOfDay = perdiemLine.TotalNoOfDay;
perdiemTableTempDB.TotalAmount = perdiemLine.TotalAmount;
perdiemTableTempDB.UserID = curUserId();
CompanyInfo = CompanyInfo::find();// Get company information.
perdiemTableTempDB.ComLogo= CopanyImage::findByRecord(companyInfo).Image;//get current company logo.
perdiemTableTempDB.insert();}
public void processReport()
{
PerdiemHeader perdimeHeader;
PerdiemLine perdiemLine;
QueryRun queryRun;
this.getReportParameters();
queryRun = new QueryRun(this.buildQuery(this.parmQuery(),PerdiemRequestID,perdiemStatus));
while (queryRun.next())
{
perdimeHeader = queryRun.get(tableNum(PerdiemHeader));
perdiemLine = queryRun.get(tableNum(PerdiemLine));
this.insertTempData(perdimeHeader,perdiemLine);
}
}
}
STEP 5 : Create a controller class:
class SMJ_PerdiemReportController extends SrsReportRunController
{
#define.ReportName('SMJ_PerdiemReport.PerdiemRequest')// Report name
SMJones_PerdiemContractClass SMJ_PerdiemContract;
//SMJ_PurchaseOrder SMJ_PurchaseOrder ;
PerdiemHeader perdiemheader;
//protected void prePromptModifyContract() //Pass parameter to contract
//{
// if (this.parmArgs() && this.parmArgs().record() && this.parmArgs().dataset() == tableNum(PerdiemHeader))
// {
// perdiemheader = this.parmArgs().record();
// }
// if (!SMJ_PerdiemContract)
// {
// SMJ_PerdiemContract = this.parmReportContract().parmRdpContract();
// }
// SMJ_PerdiemContract.parmPerdiemRequestID(perdiemheader.PerdiemRequestID);
// super();
//}
public void setRange(Args _args, Query _query) //set range to query
{
QueryBuildDataSource qbds;
QueryBuildRange qbr;
if (_args && _args.dataset())
{
switch(_args.dataset())
{
case tableNum(PerdiemHeader) :
perdiemheader = _args.record();
break;
}
}
qbds = _query.dataSourceTable(tableNum(PerdiemHeader));
qbds.clearRanges();
if (!qbr)
{
qbr = qbds.addRange(fieldNum(PerdiemHeader, PerdiemRequestID));
}
if(perdiemheader)
{
qbr.value(perdiemheader.PerdiemRequestID);
}
}
public boolean showQueryValues(str parameterName)
{
return true;
}
public static SMJ_PerdiemReportController construct(Args _args)
{
SMJ_PerdiemReportController controller=new SMJ_PerdiemReportController();
controller.parmArgs(_args);
return controller;
}
public static void main(Args _args)
{
SMJ_PerdiemReportController controller = new SMJ_PerdiemReportController();
controller.parmReportName(#ReportName);
controller.parmArgs(_args);
controller.setRange(_args, controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()));
controller.parmShowDialog(false);// if give true contract class dialog will show.
controller.startOperation();
}
}
Contract class dialog:
user can give data for filter purpose.
Output:
1 Get current company name:
=Microsoft.Dynamics.Framework.Reports.DataMethodUtility.GetFullCompanyNameForUser(Parameters!AX_CompanyName.Value, Parameters!AX_UserContext.Value)
write this code in report design «Expr» expression.
2 Page number:
="Page " & space(1) &Globals!PageNumber &" of "&Globals!TotalPages
3 Get time and date:
=Microsoft.Dynamics.Framework.Reports.DataMethodUtility.ConvertUtcToAxUserTimeZoneForUser(Parameters!AX_CompanyName.Value, Parameters!AX_UserContext.Value, System.DateTime.UtcNow, "d", Parameters!AX_RenderingCulture.Value) & vbCrLf & Microsoft.Dynamics.Framework.Reports.DataMethodUtility.ConvertUtcToAxUserTimeZoneForUser(Parameters!AX_CompanyName.Value, Parameters!AX_UserContext.Value, System.DateTime.UtcNow, "t", Parameters!AX_RenderingCulture.Value)
write this code in report design «Expr» expression.
Comments
Post a Comment