Hi All,
Scenario:
I' m facing one issue while creating record. I'm using plugin to create record and inside custom action and while creating record, passing current date and time to the one field called as "End Date"
It showing one hour late in crm plugin. (Inside trace log it showing accurate value)
Approaches tried:
1. DateTime CurrentDate = DateTime.Now.ToLocalTime();
2. Using User time zone.
public int? RetrieveCurrentUsersSettings(IOrganizationService service, Guid ContextUserid)
{
Guid UserId = ContextUserid;
var currentUserSettings = service.RetrieveMultiple(
new QueryExpression("usersettings")
{
ColumnSet = new ColumnSet("timezonecode"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("systemuserid", ConditionOperator.In, new Guid[] { UserId })
}
}
}).Entities[0].ToEntity<Entity>();
//return time zone code
return (int?)currentUserSettings.Attributes["timezonecode"];
}
public DateTime RetrieveLocalTimeFromUTCTime(DateTime utcTime, int? timeZoneCode, IOrganizationService service)
{
if (!timeZoneCode.HasValue)
return DateTime.Now;
var request = new LocalTimeFromUtcTimeRequest
{
TimeZoneCode = timeZoneCode.Value,
UtcTime = utcTime.ToUniversalTime()
};
var response = (LocalTimeFromUtcTimeResponse)service.Execute(request);
return response.LocalTime;
}
Also behavior of date field is already "User Local"
Any help will be appreciated
*This post is locked for comments