在CRM数据库中存储的时间都是UTC时间,所以当我们在做报表的时候需要将UTC时间转换为本地时间。
对于CRM On-premise来说,我们可以使用Filtered View,比如Filteredaccount里就有createdon和createdonUTC两列,createdon里的值就是本地时间了。
但对于 CRM Online来说,我们需要使用Fetch XML来query数据,就无法使用FilteredView了。我们从数据库中query来的只有UTC时间,我们需要在报表中将它转换为本地时间。如果你利用ReportWizard来生成一个最简单的报表,并包含一个createdon列在报表的table中,我们就可以看到这个转换函数了:
Microsoft.Crm.Reporting.RdlHelper.DateTimeUtility.ConvertUtcToLocalTime(Fields!createdonValue.Value,Parameters!CRM_UserTimeZoneName.Value)
下面我把整个xml拷贝下来:
<Textbox Name="Table0_Header1">
<CanGrow>true</CanGrow>
<UserSort>
<SortExpression>=Microsoft.Crm.Reporting.RdlHelper.DateTimeUtility.ConvertUtcToLocalTime(Fields!createdonValue.Value, Parameters!CRM_UserTimeZoneName.Value)</SortExpression>
</UserSort>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>="Gemaakt op"</Value>
<Style>
<FontFamily>Tahoma</FontFamily>
<FontSize>8pt</FontSize>
<FontWeight>Bold</FontWeight>
<Color>#ffffff</Color>
<Language>nl-NL</Language>
</Style>
</TextRun>
</TextRuns>
<Style>
<TextAlign>Center</TextAlign>
</Style>
</Paragraph>
</Paragraphs>
<Style>
<BackgroundColor>#4f81bd</BackgroundColor>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
本文详细介绍了在CRM数据库中存储时间均为UTC时间的情况下,如何在报表中将其转换为本地时间,以实现更符合用户需求的时间显示。特别针对CRMOnline场景,通过使用FetchXML查询数据并结合特定函数实现UTC时间到本地时间的转换,同时提供了具体的XML示例代码,便于读者快速上手。
246

被折叠的 条评论
为什么被折叠?



