UI Builder Class Overview
User Interface (UI) Builder Class is used to define the layout of the parameter dialog box that opens before a report is run in Microsoft Dynamics AX. It is used to add the customizations as well as additional fields in the dialog.
Following are the scenarios where UI Builder Class can be used:
Grouping dialog fields
Overriding dialog field events
Adding a customized lookup to a dialog field
Binding dialog fields with Report contract parameters
Changing the layout of the dialog
Adding custom controls to the dialog
To create a UI builder class, extend it with SrsReportDataContractUIBuilder.
UI Builder Class helps you to add run time lookups and other controls on the dialog form.
class SimpleDemoUIBuilder extends SrsReportDataContractUIBuilder
{
DialogField dialogEmplId;
SimpleDemoContract contract;
}
public void build()
{
contract = this.dataContractObject();
dialogEmplId = this.addDialogField(methodStr(SimpleDemoContract, parmEmplId),contract);
}
private void emplIdLookup(FormStringControl emplIdlookup)
{
Query query = new Query();
QueryBuildDataSource qbds_EmplTable;
SysTableLookup sysTableLookup;
// Create an instance of SysTableLookup with the current calling form control.
sysTableLookup = SysTableLookup::newParameters(tableNum(CustTable), emplIdlookup);
// Add fields to be shown in the lookup form.
sysTableLookup.addLookupfield(fieldNum(CustTable,AccountNum));
qbds_EmplTable = query.addDataSource(tableNum(CustTable));
sysTableLookup.parmQuery(query);
// Perform the lookup
sysTableLookup.performFormLookup();
}
public void getFromDialog()
{
contract = this.dataContractObject();
super();
}
public void initializeFields()
{
contract = this.dataContractObject();
}
public void postBuild()
{
super();
dialogEmplId = this.bindInfo().getDialogField(this.dataContractObject(),methodStr(SimpleDemoContract,parmEmplId));
dialogEmplId.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(SimpleDemoUIBuilder,emplIdLookup), this);
//dialogEmplId.lookupButton(2);
}
2.Create the new class :-
[DataContractAttribute,SysOperationContractProcessingAttribute(classstr(SimpleDemoUIBuilder))]
//example of the contract class validation and initialization "HcmBirthdayContract"
public class SimpleDemoContract implements SysOperationValidatable, SysOperationInitializable
{
EmplId emplId;
}
public void initialize()
{
this.parmEmplId('');
}
[DataMemberAttribute("EmplId"),
SysOperationLabelAttribute('EMPLID')
]
public EmplId parmEmplId(EmplId _emplId = emplId)
{
emplId = _emplId;
return emplId;
}
/// <summary>
/// Validates the SSRS report parameters.
/// </summary>
/// <returns>
/// true if successful; otherwise, false.
/// </returns>
public boolean validate()
{
boolean ret = true;
if (!emplId)
{
ret = checkFailed("Please select the emplid");
}
return ret;
}
3.Create the new class :-
[
SRSReportQueryAttribute(queryStr(cust)),
SRSReportParameterAttribute(classstr(SimpleDemoContract))
]
class SimpleDemoDemoDP extends SRSReportDataProviderBase
{
SimpleDemoTmp SimpleDemoTmp;
Custtable custtable;
}
[SRSReportDataSetAttribute("SimpleDemoTmp")]
public SimpleDemoTmp getSimpleDemoTmp()
{
select * from SimpleDemoTmp;
return SimpleDemoTmp;
}
public void insertTmpTable()
{
SimpleDemoTmp.EmplId = custtable.AccountNum;
SimpleDemoTmp.insert();
}
[SysEntryPointAttribute(false)]
public void ProcessReport()
{
EmplId emplId;
SimpleDemoContract contract;
;
contract = this.parmDataContract() as SimpleDemoContract;
emplId = contract.parmEmplId();
select * from custtable where custtable.AccountNum== emplId;
this.insertTmpTable();
}
------------------------------------------------------------------------------------------
[SRSReportQueryAttribute(querystr(CustTransQuery))]
public class CustTransdemoDP extends SRSReportDataProviderBase
{
CustTransDemoTmp custTransDemoTmp;
CustTable custTable;
CustTrans custTrans;
AmountCur amountCur;
Voucher voucher;
CustGroupId custGroup;
TransDate transDate;
}
=================
[SRSReportDataSetAttribute(tableStr(CustTransDemoTmp))]
private CustTransDemoTmp getCustTransTmp()
{
select custTransDemoTmp;
return custTransDemoTmp;
}
======================
private void inserrtIntoCustTransTmp()
{
custTransDemoTmp.CustGroup = custTable.CustGroup;
custTransDemoTmp.AmountCur = custTrans.AmountCur;
custTransDemoTmp.Voucher = custTrans.Voucher;
custTransDemoTmp.TransDate = custTrans.TransDate;
custTransDemoTmp.insert();
}
=======================
[SysEntryPointAttribute]
public void processReport()
{
QueryRun queryRun;
queryRun = new QueryRun(this.parmQuery());
while (queryRun.next())
{
custTable = queryRun.get(tablenum(CustTable));
custTrans = queryRun.get(tablenum(CustTrans));
amountCur = custTrans.AmountCur;
voucher = custTrans.Voucher;
custGroup = custTable.CustGroup;
transDate = custTrans.TransDate;
this.inserrtIntoCustTransTmp();
}
}
http://www.dynamics101.com/2014/04/using-ui-builder-class-to-develop-ssrs-reports-microsoft-dynamics-ax-2012/
controller class :-
/// <summary>
/// The <c>HcmADARequirementController</c> class is a controller class for the <c>HcmADARequirement</c>
/// report.
/// </summary>
class StockTransferController extends SrsReportRunController
{
InventTransferShipmentContract inventTransferContract;
InventTransferId transferId;
Voucher voucher;
InventTransferJour transferJour;
#define.ReportName('StockTransferShipment.PrecisionDesign1')
#define.TransferId('ShipmentDs_TransferId')
#define.VoucherId('ShipmentDs_Voucher')
}
public client static void main(Args _args)
{
StockTransferController controller = new StockTransferController();
controller.parmReportName(#ReportName);
controller.parmLoadFromSysLastValue(false);
controller.parmArgs(_args);
controller.parmShowDialog(false);
controller.startOperation();
}
/// <summary>
/// Opens the report if the record context is not null.
/// </summary>
/// <returns>
/// true if the record context is not empty; otherwise, false.
/// </returns>
/// <remarks>
/// The report will get executed if the record context is not null.
/// </remarks>
public boolean processReportParameters()
{
if (this.parmArgs() && this.parmArgs().record())
{
transferJour = this.parmArgs().record();
transferId = transferJour.TransferId;
voucher = transferJour.VoucherId;
return false;
}
else
{
checkFailed("@SYS22539");
return false;
}
}
/// <summary>
/// Override this method to change the report contract before you run the report.
/// </summary>
public void preRunModifyContract()
{
SrsReportRdlDataContract rdlContractInfo;
rdlContractInfo = this.parmReportContract().parmRdlContract();
inventTransferContract = this.parmReportContract().parmRdpContract() as InventTransferShipmentContract;
//inventTransferContract.parmJourId(transferJour.TransferId);
//inventTransferContract.parmVoucher(transferJOur.VoucherId);
rdlContractInfo.setValue(#TransferId, transferJour.TransferId);
rdlContractInfo.setValue(#VoucherId, transferJour.VoucherId);
}
/// <summary>
/// The <c>InventTransferShipmentContract</c> class is the <c>Invent shipment contract</c> report
/// </summary>
/// <remarks>
///
/// </remarks>
[
DataContractAttribute
]
public class InventTransferShipmentContract implements SysOperationValidatable
{
InventTransferId transferId;
Voucher voucher;
}
[
DataMemberAttribute('TransferId'),
SysOperationLabelAttribute('Transfer Id')
]
public InventTransferId parmJourId(InventTransferId _transferId = transferId)
{
transferId = _transferId;
return transferId;
}
[
DataMemberAttribute('Voucher')
]
public Voucher parmVoucher(voucher _voucher = voucher)
{
voucher = _voucher;
return voucher;
}
public boolean validate()
{
boolean ret = true;
/*
if (! voucher || ! transferId)
{
ret = checkFailed("Filters must be supplied");
}
*/
return ret;
}
[
SRSReportParameterAttribute(classStr(InventTransferShipmentContract))]
public class InventTransferShipDP extends SrsReportDataProviderBase
//SrsReportDataProviderPreProcess
{
InventTransferCommon_Tmp inventShipment;
InventTransferId transferId;
Voucher voucher;
}
[
SRSReportDataSetAttribute(tablestr(InventTransferCommon_Tmp))
]
public InventTransferCommon_Tmp getInventTransferCommon_Tmp()
{
select inventShipment;
return inventShipment;
}
[SysEntryPointAttribute]
public void processReport()
{
InventTransferJour transferJour;
InventTransferJourLine jourLine;
InventTransferShipmentContract contract = this.parmDataContract() as InventTransferShipmentContract;
InventSiteId inventSiteId;
InventTransferTable transferTable;
InventTable inventTable;
super();
//Parameters -- initialization
transferId = contract.parmJourId();
voucher = contract.parmVoucher();
//End
while select jourLine
join transferJour
where transferJour.TransferId == jourLine.TransferId
&& transferJour.VoucherId == jourLine.VoucherId
&& transferJour.UpdateType == InventTransferUpdateType::Shipment
&& transferJour.TransferId == transferId
&& transferJour.VoucherId == voucher
{
transferTable = transferJour.inventTransferTable();
inventTable = inventTable::find(jourLine.ItemId);
inventSiteId = InventLocation::find(transferJour.InventLocationIdFrom).InventSiteId;
inventShipment.FirmName = InventSite::find(inventSiteId).Name;
inventShipment.FromWarehouse = transferJour.InventLocationIdFrom;
inventShipment.ToWarehouse = transferJour.InventLocationIdTo;
inventShipment.InventTransferId = transferJour.TransferId;
inventShipment.DeliveryMode = transferTable.DlvModeId;
inventShipment.VehicleNum = transferTable.VehicleNum;
inventShipment.BPGroup = inventTable.BPGroupName();
inventShipment.ProductGroup = inventTable.productGroupName();
inventShipment.ItemName = inventTable.itemName();
inventShipment.ItemId = inventTable.ItemId;
inventShipment.ShipmentQty = jourLine.QtyShipped;
inventShipment.InventoryUnit = jourLine.UnitId;
inventShipment.insert();
}
}
User Interface (UI) Builder Class is used to define the layout of the parameter dialog box that opens before a report is run in Microsoft Dynamics AX. It is used to add the customizations as well as additional fields in the dialog.
Following are the scenarios where UI Builder Class can be used:
Grouping dialog fields
Overriding dialog field events
Adding a customized lookup to a dialog field
Binding dialog fields with Report contract parameters
Changing the layout of the dialog
Adding custom controls to the dialog
To create a UI builder class, extend it with SrsReportDataContractUIBuilder.
UI Builder Class helps you to add run time lookups and other controls on the dialog form.
class SimpleDemoUIBuilder extends SrsReportDataContractUIBuilder
{
DialogField dialogEmplId;
SimpleDemoContract contract;
}
public void build()
{
contract = this.dataContractObject();
dialogEmplId = this.addDialogField(methodStr(SimpleDemoContract, parmEmplId),contract);
}
private void emplIdLookup(FormStringControl emplIdlookup)
{
Query query = new Query();
QueryBuildDataSource qbds_EmplTable;
SysTableLookup sysTableLookup;
// Create an instance of SysTableLookup with the current calling form control.
sysTableLookup = SysTableLookup::newParameters(tableNum(CustTable), emplIdlookup);
// Add fields to be shown in the lookup form.
sysTableLookup.addLookupfield(fieldNum(CustTable,AccountNum));
qbds_EmplTable = query.addDataSource(tableNum(CustTable));
sysTableLookup.parmQuery(query);
// Perform the lookup
sysTableLookup.performFormLookup();
}
public void getFromDialog()
{
contract = this.dataContractObject();
super();
}
public void initializeFields()
{
contract = this.dataContractObject();
}
public void postBuild()
{
super();
dialogEmplId = this.bindInfo().getDialogField(this.dataContractObject(),methodStr(SimpleDemoContract,parmEmplId));
dialogEmplId.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(SimpleDemoUIBuilder,emplIdLookup), this);
//dialogEmplId.lookupButton(2);
}
2.Create the new class :-
[DataContractAttribute,SysOperationContractProcessingAttribute(classstr(SimpleDemoUIBuilder))]
//example of the contract class validation and initialization "HcmBirthdayContract"
public class SimpleDemoContract implements SysOperationValidatable, SysOperationInitializable
{
EmplId emplId;
}
public void initialize()
{
this.parmEmplId('');
}
[DataMemberAttribute("EmplId"),
SysOperationLabelAttribute('EMPLID')
]
public EmplId parmEmplId(EmplId _emplId = emplId)
{
emplId = _emplId;
return emplId;
}
/// <summary>
/// Validates the SSRS report parameters.
/// </summary>
/// <returns>
/// true if successful; otherwise, false.
/// </returns>
public boolean validate()
{
boolean ret = true;
if (!emplId)
{
ret = checkFailed("Please select the emplid");
}
return ret;
}
3.Create the new class :-
[
SRSReportQueryAttribute(queryStr(cust)),
SRSReportParameterAttribute(classstr(SimpleDemoContract))
]
class SimpleDemoDemoDP extends SRSReportDataProviderBase
{
SimpleDemoTmp SimpleDemoTmp;
Custtable custtable;
}
[SRSReportDataSetAttribute("SimpleDemoTmp")]
public SimpleDemoTmp getSimpleDemoTmp()
{
select * from SimpleDemoTmp;
return SimpleDemoTmp;
}
public void insertTmpTable()
{
SimpleDemoTmp.EmplId = custtable.AccountNum;
SimpleDemoTmp.insert();
}
[SysEntryPointAttribute(false)]
public void ProcessReport()
{
EmplId emplId;
SimpleDemoContract contract;
;
contract = this.parmDataContract() as SimpleDemoContract;
emplId = contract.parmEmplId();
select * from custtable where custtable.AccountNum== emplId;
this.insertTmpTable();
}
//Or
------------------------------------------------------------------------------------------
[SRSReportQueryAttribute(querystr(CustTransQuery))]
public class CustTransdemoDP extends SRSReportDataProviderBase
{
CustTransDemoTmp custTransDemoTmp;
CustTable custTable;
CustTrans custTrans;
AmountCur amountCur;
Voucher voucher;
CustGroupId custGroup;
TransDate transDate;
}
=================
[SRSReportDataSetAttribute(tableStr(CustTransDemoTmp))]
private CustTransDemoTmp getCustTransTmp()
{
select custTransDemoTmp;
return custTransDemoTmp;
}
======================
private void inserrtIntoCustTransTmp()
{
custTransDemoTmp.CustGroup = custTable.CustGroup;
custTransDemoTmp.AmountCur = custTrans.AmountCur;
custTransDemoTmp.Voucher = custTrans.Voucher;
custTransDemoTmp.TransDate = custTrans.TransDate;
custTransDemoTmp.insert();
}
=======================
[SysEntryPointAttribute]
public void processReport()
{
QueryRun queryRun;
queryRun = new QueryRun(this.parmQuery());
while (queryRun.next())
{
custTable = queryRun.get(tablenum(CustTable));
custTrans = queryRun.get(tablenum(CustTrans));
amountCur = custTrans.AmountCur;
voucher = custTrans.Voucher;
custGroup = custTable.CustGroup;
transDate = custTrans.TransDate;
this.inserrtIntoCustTransTmp();
}
}
http://www.dynamics101.com/2014/04/using-ui-builder-class-to-develop-ssrs-reports-microsoft-dynamics-ax-2012/
controller class :-
/// <summary>
/// The <c>HcmADARequirementController</c> class is a controller class for the <c>HcmADARequirement</c>
/// report.
/// </summary>
class StockTransferController extends SrsReportRunController
{
InventTransferShipmentContract inventTransferContract;
InventTransferId transferId;
Voucher voucher;
InventTransferJour transferJour;
#define.ReportName('StockTransferShipment.PrecisionDesign1')
#define.TransferId('ShipmentDs_TransferId')
#define.VoucherId('ShipmentDs_Voucher')
}
public client static void main(Args _args)
{
StockTransferController controller = new StockTransferController();
controller.parmReportName(#ReportName);
controller.parmLoadFromSysLastValue(false);
controller.parmArgs(_args);
controller.parmShowDialog(false);
controller.startOperation();
}
/// <summary>
/// Opens the report if the record context is not null.
/// </summary>
/// <returns>
/// true if the record context is not empty; otherwise, false.
/// </returns>
/// <remarks>
/// The report will get executed if the record context is not null.
/// </remarks>
public boolean processReportParameters()
{
if (this.parmArgs() && this.parmArgs().record())
{
transferJour = this.parmArgs().record();
transferId = transferJour.TransferId;
voucher = transferJour.VoucherId;
return false;
}
else
{
checkFailed("@SYS22539");
return false;
}
}
/// <summary>
/// Override this method to change the report contract before you run the report.
/// </summary>
public void preRunModifyContract()
{
SrsReportRdlDataContract rdlContractInfo;
rdlContractInfo = this.parmReportContract().parmRdlContract();
inventTransferContract = this.parmReportContract().parmRdpContract() as InventTransferShipmentContract;
//inventTransferContract.parmJourId(transferJour.TransferId);
//inventTransferContract.parmVoucher(transferJOur.VoucherId);
rdlContractInfo.setValue(#TransferId, transferJour.TransferId);
rdlContractInfo.setValue(#VoucherId, transferJour.VoucherId);
}
/// <summary>
/// The <c>InventTransferShipmentContract</c> class is the <c>Invent shipment contract</c> report
/// </summary>
/// <remarks>
///
/// </remarks>
[
DataContractAttribute
]
public class InventTransferShipmentContract implements SysOperationValidatable
{
InventTransferId transferId;
Voucher voucher;
}
[
DataMemberAttribute('TransferId'),
SysOperationLabelAttribute('Transfer Id')
]
public InventTransferId parmJourId(InventTransferId _transferId = transferId)
{
transferId = _transferId;
return transferId;
}
[
DataMemberAttribute('Voucher')
]
public Voucher parmVoucher(voucher _voucher = voucher)
{
voucher = _voucher;
return voucher;
}
public boolean validate()
{
boolean ret = true;
/*
if (! voucher || ! transferId)
{
ret = checkFailed("Filters must be supplied");
}
*/
return ret;
}
[
SRSReportParameterAttribute(classStr(InventTransferShipmentContract))]
public class InventTransferShipDP extends SrsReportDataProviderBase
//SrsReportDataProviderPreProcess
{
InventTransferCommon_Tmp inventShipment;
InventTransferId transferId;
Voucher voucher;
}
[
SRSReportDataSetAttribute(tablestr(InventTransferCommon_Tmp))
]
public InventTransferCommon_Tmp getInventTransferCommon_Tmp()
{
select inventShipment;
return inventShipment;
}
[SysEntryPointAttribute]
public void processReport()
{
InventTransferJour transferJour;
InventTransferJourLine jourLine;
InventTransferShipmentContract contract = this.parmDataContract() as InventTransferShipmentContract;
InventSiteId inventSiteId;
InventTransferTable transferTable;
InventTable inventTable;
super();
//Parameters -- initialization
transferId = contract.parmJourId();
voucher = contract.parmVoucher();
//End
while select jourLine
join transferJour
where transferJour.TransferId == jourLine.TransferId
&& transferJour.VoucherId == jourLine.VoucherId
&& transferJour.UpdateType == InventTransferUpdateType::Shipment
&& transferJour.TransferId == transferId
&& transferJour.VoucherId == voucher
{
transferTable = transferJour.inventTransferTable();
inventTable = inventTable::find(jourLine.ItemId);
inventSiteId = InventLocation::find(transferJour.InventLocationIdFrom).InventSiteId;
inventShipment.FirmName = InventSite::find(inventSiteId).Name;
inventShipment.FromWarehouse = transferJour.InventLocationIdFrom;
inventShipment.ToWarehouse = transferJour.InventLocationIdTo;
inventShipment.InventTransferId = transferJour.TransferId;
inventShipment.DeliveryMode = transferTable.DlvModeId;
inventShipment.VehicleNum = transferTable.VehicleNum;
inventShipment.BPGroup = inventTable.BPGroupName();
inventShipment.ProductGroup = inventTable.productGroupName();
inventShipment.ItemName = inventTable.itemName();
inventShipment.ItemId = inventTable.ItemId;
inventShipment.ShipmentQty = jourLine.QtyShipped;
inventShipment.InventoryUnit = jourLine.UnitId;
inventShipment.insert();
}
}
No comments:
Post a Comment