Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Date time field showing one hour late if record created using CRM custom action

Posted on by 5,227

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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans