In Dynamics CRM Online, if we want to show the current date and time in a custom SSRS report (e.g. report executed date and time), we always get the UTC date. Even if you set the report’s language properties, this is the behaviour. You will see this behaviour only once you have deployed the report to CRM. When you preview the report, you will see the correct date and time.
After researching a good number of hours on this matter, we found the below solution.
We have to refer a Dynamics CRM dll in the report and use the Microsoft.Crm.Reporting.RdlHelper.DateTimeUtility.ConvertUtcToLocalTime
function in the expression.
Step 1:
Create a hidden Parameter and set the properties as below.
Step 2:
Right click outside the report body and click report properties.
Click References and add the following reference:
Microsoft.Crm.Reporting.RdlHelper, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Step 3:
Add the text field you want to show the current date and set the following expression:
=CDate(Microsoft.Crm.Reporting.RdlHelper.DateTimeUtility.ConvertUtcToLocalTime(DateTime.UtcNow, Parameters!CRM_UserTimeZoneName.Value))
Trick is, when you preview the report inside BIDS, you get an error like below:
Once you deployed the report you should see the report correctly with current date and time.
No comments:
Post a Comment