MS CRM 2011 设置报表内容格式

 

原创地址:http://www.cnblogs.com/jfzhu/archive/2013/01/31/2886280.html

转载请注明出处

 

我在前面的博客中介绍过,CRM 2011的报表有基于SQL的报表基于Fetch的报表。基于SQL的报表只可以在On-Premise的CRM中使用,而基于Fetch的报表则既可以在On-Premise使用,也可以在Online中使用。我在本文中分别介绍如何设置基于SQL的报表的格式,和基于Fetch的报表的格式。

 

在CRM中,用户可以在personal options中设置自己的格式。比如我在CRM中设置为荷兰(语)的格式。我希望CRM的报表中的格式和我在personal options中设置的格式相同。

image

 

当然如果你不必要求报表的格式与personal options中设置的格式相同,你可以在报表中hard code你的格式:

image

 

如果报表的格式要求与personal options中设置的格式相同:

 

(一) 基于SQL的报表

 

 

1. 使用Filtered View:

sdk中已经明确讲了,在报表中使用Filtered View,比如FilteredAccount,FilteredOpportunity。即便是自定义的Entity,系统也为其会生成一个FilteredEntityName的 Filtered View。

 

2. 在报表中需要添加一个数据集 DSNumandCurrency

该数据集可以获得用户的当前设置,需要利用该数据集来设置报表的格式。

Query 为: select * from dbo.fn_GetFormatStrings()

 

image

 

3. option set field

option set field 在Filtered View中有两列,fieldname显示value,fieldnamename显示label。以opportunity的 opportunityratingcode 为例, FilteredOpportunity中分别有 opportunityratingcode 表示 value 和 opportunityratingcodename 来表示 label,用户设置不同的语言会显示相应的label。

 

4. Date and Time field

DateTime field在 Filtered View中也有两列,fieldname为本地时间,fieldnameutc为UTC时间。 比如createdon 为本地时间, createdonutc 为 UTC时间。通常我们要显示的都是本地时间。

对Textbox的Format属性需要进行设置:

image

Date:    =First(Fields!DateFormat.Value, "DSNumandCurrency")

Time:   =First(Fields!TimeFormat.Value, "DSNumandCurrency")

 

5. Number field

number field 只有一列,使用的format为:

Integer
=First(Fields!NumberFormat_0_Precision.Value, "DSNumandCurrency")
 
Decimal with 2-decimal points precision
=First(Fields!NumberFormat_2_Precision.Value, "DSNumandCurrency")

 

对于 Number field,除了要设置Textbox的Format之外,还要设置Textbox的language属性,因为有的国家使用不同的小数点或者千位分隔符号,比如荷兰使用,做小数点,使用 . 做千分符。

添加一个参数:CRM_NumberLanguageCode

image

image

image

image

 

然后将Textbox的Language属性设置为:=Parameters!CRM_NumberLanguageCode.Value

image

 

6. Currency field

Currency field也有两列 fieldname和 fieldname_base,以opportunity 的 estimatedvalue 为例,这两列分别为estimatedvalue 和 estimatedvalue_base。在基于SQL的报表中,它们并没有什么区别。使用的format为:

=Fields!crm_moneyformatstring.Value 也可以为 =First(Fields!CurrencyFormat_2_Precision.Value, "DSNumandCurrency")。当然如果你要求的小数点精度不同,你可以选择不同的CurrencyFormat_X_Precision。

 

和 number field一样,currency field 也需要设置 Language 属性,=Parameters!CRM_NumberLanguageCode.Value

 

 

 

(二) 基于Fetch的报表

 

 

1. option set field

类似于SQL报表,option set field也有两列,fieldname显示value,fieldnameName显示label。以opportunity的 opportunityratingcode 为例, opportunityratingcode 表示 value, opportunityratingcodeName 表示 label,用户设置不同的语言会显示相应的label。

 

2. Date and Time field

类似SQL报表,DateTime field也有两列,fieldname为本地时间,fieldnameValue为UTC时间。 比如createdon 为本地时间, createdonValue 为 UTC时间。fieldnameValue 不仅是UTC时间,而且是日期 + 时间。 fieldname 如果设置的是只显示日期,则返回的只有日期,没有时间;如果设置的是显示日期 + 时间,则返回的也是日期 + 时间。此外, fieldname 还会按照用户 personal options中设置的格式来现实日期和时间,不需要象基于SQL的报表那样额外设置format。

 

3. Number field

number field 返回两列,fieldname 和 fieldnameValue。fieldname 按照用户personal options中设置的格式显示数字,而 fieldnameValue显示的是原始数字。如果不使用aggregation function的话,只使用 fieldname 就符合用户的personal option 的格式设置了。如果用Aggregation,必须用fieldnameValue,比如Sum(Fields!discountpercentageValue.Value)。对于 decimal的精度只能hard code了。

image

 

使用Aggregation,如果需要考虑千分符和小数点的符号的变化,可以设置Language属性,=Microsoft.Crm.Reporting.RdlHelper.ReportCultureInfo.GetCultureInfo(Parameters)

 

4. Currency field

Currency field也有两列 fieldname和 fieldnameValue,以opportunity 的 estimatedvalue 为例,这两列分别为estimatedvalue 和 estimatedvalueValue。estimatedvalue 符合用户personal options中设置的格式,货币符号使用的也是opportunity所使用的货币,estimatedvalueValue 返回的则是单纯的数字。如果不使用 aggregation function,则用fieldname 完全符合用户personal options 中对格式的设置。如果使用aggregation function,则需要使用 fieldnameValue 来进行计算。比如Sum,=CDbl(Sum(Fields!discountpercentageValue.Value)).ToString("C2", Microsoft.Crm.Reporting.RdlHelper.ReportCultureInfo.GetCultureInfo(Parameters))。Textbox的Language属性就不需要再设置了。

 

 

 

总结:

 

image

 

 

 

posted @ 2013-01-31 07:25  AI观星台  阅读(1518)  评论(0编辑  收藏  举报