如何在D365FO创建SSRS报表(一)Report Data Provider Class(how-to-create-ssrs-report-in-d365fo-part1-report-data-provider-class)

Report data provider class

继承SrsReportDataProviderPreProcessTempDB

声明所用到的Contract 和 Query还有其他变量

[
    SRSReportParameterAttribute(classStr(Demo_InventJournalTransTransferContract)),
    SRSReportQueryAttribute(queryStr(Demo_InventJournalTransTransferQuery))
]
class Demo_InventJournalTransTransferDP extends SrsReportDataProviderPreProcessTempDB
{
}

SRSReportDataSetAttribute

定义临时表保存报表的Header,Footer 等数据

[
    SRSReportDataSetAttribute('Demo_InventJournalTransTransferHeaderTMP')
]
public Demo_InventJournalTransTransferHeaderTMP getHeader()
{
    select * from header;
    return header;
}
 
[
    SRSReportDataSetAttribute('Demo_InventJournalTransTransferFooterTMP')
]
public Demo_InventJournalTransTransferFooterTMP getFooter()
{
    select * from footer;
    return footer;
}

Process report

处理报表的数据

public void processReport()
{
    Demo_InventJournalTransTransferContract contract            = this.parmDataContract();
 
    super();
 
    inventDimParm       = this.initInventDimParm(contract);
    inventDimSetup      = this.getInventDimFieldList();
 
    this.fetchDetail();
    this.fetchHeader();
    this.fetchFooter();
 
}

如何添加公司LOGO

CompanyInfo companyInfo = CompanyInfo::find();
tableBuffer.CompanyLogo = CompanyImage::findByRecord(companyInfo).Image;

Query中使用临时表

注意:在报表抓取数据的时候我们经常会用到Query而不是while select,在Query中使用临时表,只需要加上setCursor() (or setRecord()),下面是一个例子:

TmpTableName name;
 
name.RefTableId = 1;
name.TableName = 'TableA';
name.insert();
 
TmpTableIdMap map;
map.MainTableId = 1;
map.MainFieldId = 42;
map.insert();
 
Query query = new Query();
QueryBuildDataSource nameDs = query.addDataSource(tableNum(TmpTableName));
 
QueryBuildDataSource mapDs = nameDs.addDataSource(tableNum(TmpTableIdMap));
mapDs.addLink(fieldNum(TmpTableName, RefTableId), fieldNum(TmpTableIdMap, MainTableId));
 
QueryRun qr = new QueryRun(query);
qr.setCursor(name);
qr.setCursor(map);
 
while (qr.next())
{
    TmpTableName nameFetched = qr.get(tableNum(TmpTableName));
    TmpTableIdMap mapFetched = qr.get(tableNum(TmpTableIdMap));
 
    info(strFmt('%1 - %2', nameFetched.TableName, mapFetched.MainFieldId));
}

有时候报表会需要显示条形码或者二维码,请参考一下链接:

One Comment

Comments are closed.