Twitter Image

Getting the CRM Server Time

Written by Stéphane Dorrekens
Wednesday, 19 June 2013 14:31

I got the query on how to get the current MSCRM server time in order to synchronize some security tokens between applications.
Unfortunately, I couldn't find any API from MSCRM to get this time (ie: Whoami only returns credentials information and the ...LocalTime.. functions only translate a given time from/to UTC), furthermore the solution had to work for CRM online which forbid deploying custom .svc or .asmx endpoints.
As the proposed pattern could be used for other information, I thought it could be useful to explain it here.

We start by creating a new entity "GetSystemInformation" with a datetime attribute

Then we create a plugin registered on the Post Retrieve event of that entity; the purpose of that plugin is to inject the current server time on the fly 

We create a record and when opening it, we can validate the current server time is fetched.

 

Then, we can call the organization web service with the Retrieve Method on that record to get the server time.

 

Note: The Server time depends on where the code actually runs; on CRM Online; you will get the Sandbox server time; not the Organization Server time.