SSRS Reports using the QueryInsertRecordSet in D 365 FO
Logic for Report Using QueryInsertRecordSet:
I used QueryInsertRecordSet that will insert the data in one trip and it is faster than insert recordset and also we are not using the contract class and it works fine.
The Key point here is that we have to make the Report Data Set Property(Dynamics Filters to True) to make the logic working. This is required to access the DP class query in the controller class.
Printing the report for selected record in the SalesQuotationJournal.
[
SRSReportQueryAttribute(queryStr(SalesQuotationQuery))
]
class gbSalesQuotationDP extends SrsReportDataProviderPreProcessTempDB
{
SalesQuotationTmpTable salesQuotationTmpTable;
CustQuotationJour custQuotationJour;
CustQuotationTrans custQuotationTrans;
/// <summary>
///
/// </summary>
private void addInsertFieldMapping(QueryBuildFieldList _fieldList, Map _fieldMapping, int _sourceTableUniqueId, FieldId _sourceFieldId, FieldName _sourceFieldName, FieldName _destinationFieldName)
{
_fieldList.addField(_sourceFieldId);
_fieldMapping.insert(_destinationFieldName, [_sourceTableUniqueId, _sourceFieldName]);
}
/// <summary>
///
/// </summary>
[
SRSReportDataSetAttribute(tableStr(SalesQuotationTmpTable))
]
public SalesQuotationTmpTable getsalesQuotationTmp()
{
select salesQuotationTmpTable;
return salesQuotationTmpTable;
}
/// <summary>
///
/// Company Details
private void insertCompanyDetails()
{
CompanyInfo companyInfo;
companyInfo = CompanyInfo::find();
salesQuotationTmpTable.Image = CompanyImage::findByRecord(companyInfo).Image;
salesQuotationTmpTable.Name = companyInfo.name();
salesQuotationTmpTable.Address = companyInfo.postalAddress().Address;
salesQuotationTmpTable.Phone = companyInfo.phone();
salesQuotationTmpTable.Email = companyInfo.email();
salesQuotationTmpTable.Fax = companyInfo.teleFax();
salesQuotationTmpTable.insert();
}
/// <summary>
///
/// </summary>
public void insertData()
{
Query query;
Map insertRecordsetMap;
QueryBuildDataSource qbdsCustQuotationJour, qbdsCustQuotationTrans;
QueryBuildFieldList qbflQuotationJour, qbfQuotationTrans;
int dataSourceUniqueIdJour, dataSourceUniqueIdTrans;
insertRecordsetMap = new Map(Types::String,Types::Container);
query = new Query(this.parmQuery());
qbdsCustQuotationJour = query.dataSourceTable(tableNum(CustQuotationJour));
qbdsCustQuotationTrans = query.dataSourceTable(tableNum(CustQuotationTrans));
qbflQuotationJour = qbdsCustQuotationJour.fields();
qbfQuotationTrans = qbdsCustQuotationTrans.fields();
dataSourceUniqueIdJour = qbdsCustQuotationJour.uniqueId();
dataSourceUniqueIdTrans = qbdsCustQuotationTrans.uniqueId();
query.clearAllFields();
//CustQuotationJour data
this.addInsertFieldMapping(qbflQuotationJour, insertRecordsetMap, dataSourceUniqueIdJour, fieldNum(CustQuotationJour, QuotationId), fieldstr(CustQuotationJour, QuotationId), fieldStr(salesQuotationTmpTable, QuotationId));
this.addInsertFieldMapping(qbflQuotationJour, insertRecordsetMap, dataSourceUniqueIdJour, fieldNum(CustQuotationJour, QuotationDate), fieldStr(CustQuotationJour, QuotationDate), fieldStr(salesQuotationTmpTable, QuotationDate));
//CustQuotationTrans data
this.addInsertFieldMapping(qbfQuotationTrans, insertRecordsetMap, dataSourceUniqueIdTrans, fieldNum(CustQuotationTrans, ItemId), fieldStr(CustQuotationTrans, ItemId), fieldStr(salesQuotationTmpTable, ItemId));
this.addInsertFieldMapping(qbfQuotationTrans, insertRecordsetMap, dataSourceUniqueIdTrans, fieldNum(CustQuotationTrans, Qty), fieldStr(CustQuotationTrans, Qty), fieldStr(salesQuotationTmpTable, Qty));
this.addInsertFieldMapping(qbfQuotationTrans, insertRecordsetMap, dataSourceUniqueIdTrans, fieldNum(CustQuotationTrans, DiscAmount), fieldStr(CustQuotationTrans, DiscAmount), fieldStr(salesQuotationTmpTable, DiscAmount));
this.addInsertFieldMapping(qbfQuotationTrans, insertRecordsetMap, dataSourceUniqueIdTrans, fieldNum(CustQuotationTrans, SalesPrice), fieldStr(CustQuotationTrans, SalesPrice), fieldStr(salesQuotationTmpTable, SalesPrice));
Query::insert_recordset(salesQuotationTmpTable, insertRecordsetMap, query);
}
/// <summary>
///
/// </summary>
[
SysEntryPointAttribute(false)
]
public void processReport()
{
this.insertCompanyDetails();
this.insertData();
}
}
Class Name-gbSalesQuotationController
public class gbSalesQuotationController extends SrsReportRunController
{
CustQuotationJour custQuotationJour;
protected void prePromptModifyContract()
{
QueryBuildDataSource qbds;
FormDataSource fds;
super();
Query query = this.parmReportContract().parmQueryContracts().lookup(this.getFirstQueryContractKey());
qbds = query.dataSourceTable(tableNum(CustQuotationJour));
qbds.clearRanges();
fds = this.parmArgs().record().dataSource();
for (custQuotationJour = getFirstSelection(fds); custQuotationJour != null; custQuotationJour = fds.getNext())
{
qbds.addRange(fieldNum(CustQuotationJour,RecId)).value(queryValue(custQuotationJour.RecId));
}
}
public static void main(Args _args)
{
gbSalesQuotationController controller = new gbSalesQuotationController();
controller.parmArgs(_args);
controller.parmReportName(ssrsReportStr(gbSalesQuotationReport, Report));
controller.startOperation();
}
}
Thanks
Dynamics 365 Learner
Comments
Post a Comment