protected override void Execute(CodeActivityContext eContext) { // Setup var context = eContext.GetExtension <IWorkflowContext>(); var serviceFactory = eContext.GetExtension <IOrganizationServiceFactory>(); var service = serviceFactory.CreateOrganizationService(context.UserId); var codeString = TimeZoneCodeString.Get(eContext); int code; if (String.IsNullOrWhiteSpace(codeString) || !Int32.TryParse(codeString, out code)) { var settings = UserSettings.GetUserSettings(service, context.UserId); code = (int)settings.Attributes["timezonecode"]; } var req = new LocalTimeFromUtcTimeRequest { TimeZoneCode = code, UtcTime = UTCDateTime.Get(eContext) }; var resp = (LocalTimeFromUtcTimeResponse)service.Execute(req); if (resp == null) { return; } LocalDateTime.Set(eContext, resp.LocalTime); }
protected override void Execute(System.Activities.CodeActivityContext context) { var workflowContext = context.GetExtension <IWorkflowContext>(); var service = this.RetrieveOrganizationService(context); DateTime utcDateTime = this.DateToEvaluate.Get(context); if (utcDateTime.Kind != DateTimeKind.Utc) { utcDateTime = utcDateTime.ToUniversalTime(); } TimeZoneSummary timeZone = StaticMethods.CalculateTimeZoneToUse(this.TimeZoneOption.Get(context), workflowContext, service); LocalTimeFromUtcTimeRequest timeZoneChangeRequest = new LocalTimeFromUtcTimeRequest() { UtcTime = utcDateTime, TimeZoneCode = timeZone.MicrosoftIndex }; LocalTimeFromUtcTimeResponse timeZoneResponse = service.Execute(timeZoneChangeRequest) as LocalTimeFromUtcTimeResponse; DateTime adjustedDateTime = timeZoneResponse.LocalTime; switch (adjustedDateTime.DayOfWeek) { case System.DayOfWeek.Sunday: this.DayOfWeekPick.Set(context, new OptionSetValue(222540000)); break; case System.DayOfWeek.Monday: this.DayOfWeekPick.Set(context, new OptionSetValue(222540001)); break; case System.DayOfWeek.Tuesday: this.DayOfWeekPick.Set(context, new OptionSetValue(222540002)); break; case System.DayOfWeek.Wednesday: this.DayOfWeekPick.Set(context, new OptionSetValue(222540003)); break; case System.DayOfWeek.Thursday: this.DayOfWeekPick.Set(context, new OptionSetValue(222540004)); break; case System.DayOfWeek.Friday: this.DayOfWeekPick.Set(context, new OptionSetValue(222540005)); break; case System.DayOfWeek.Saturday: this.DayOfWeekPick.Set(context, new OptionSetValue(222540006)); break; } this.DayOfWeekName.Set(context, adjustedDateTime.DayOfWeek.ToString()); this.DayOfMonth.Set(context, adjustedDateTime.Day); this.DayOfYear.Set(context, adjustedDateTime.DayOfYear); this.HourOfDay023.Set(context, adjustedDateTime.Hour); this.Minute.Set(context, adjustedDateTime.Minute); this.MonthOfYearInt.Set(context, adjustedDateTime.Month); this.MonthOfYearPick.Set(context, new OptionSetValue(222540000 + adjustedDateTime.Month - 1)); this.MonthOfYearName.Set(context, System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(adjustedDateTime.Month)); this.Year.Set(context, adjustedDateTime.Year); }
//function for converting UTC Time Zone to Local private static DateTime RetrieveLocalTimeFromUTCTime(IOrganizationService _serviceProxy, DateTime utcTime, int?_timeZoneCode) { if (!_timeZoneCode.HasValue) { return(utcTime); } var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = _timeZoneCode.Value, UtcTime = utcTime.ToUniversalTime() }; var response = (LocalTimeFromUtcTimeResponse)_serviceProxy.Execute(request); return(response.LocalTime); }
protected override void Execute(CodeActivityContext context) { IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = context.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId); DateTime utcDateTime = this.DateToEvaluate.Get(context); if (utcDateTime.Kind != DateTimeKind.Utc) { utcDateTime = utcDateTime.ToUniversalTime(); } var settings = service.Retrieve("usersettings", workflowContext.UserId, new ColumnSet("timezonecode")); LocalTimeFromUtcTimeRequest timeZoneChangeRequest = new LocalTimeFromUtcTimeRequest() { UtcTime = utcDateTime, TimeZoneCode = int.Parse(settings["timezonecode"].ToString()) }; LocalTimeFromUtcTimeResponse timeZoneResponse = service.Execute(timeZoneChangeRequest) as LocalTimeFromUtcTimeResponse; this.ForammtedDateTimeOutput.Set(context, String.Format("{0:f}", timeZoneResponse.LocalTime)); }
private LocalTimeFromUtcTimeResponse ExecuteInternal(LocalTimeFromUtcTimeRequest request) { var timeZone = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneCodeMappings.Value[request.TimeZoneCode]); var localTime = TimeZoneInfo.ConvertTime(request.UtcTime, timeZone); return(new LocalTimeFromUtcTimeResponse { Results = { ["LocalTime"] = localTime } }); }
public DateTime LocalTimeFromUTCTime(DateTime utcTime, int timeZoneCode, IOrganizationService service) { var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = timeZoneCode, UtcTime = utcTime.ToUniversalTime() }; var response = (LocalTimeFromUtcTimeResponse)service.Execute(request); return(response.LocalTime); }
public static Result RetrieveLocalTimeFromUTCTime(DateTime utcTime, int timeZoneCode, CubeBase Cube) { var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = timeZoneCode, UtcTime = utcTime.ToUniversalTime() }; Result result = Cube.XRMActions.Execute<LocalTimeFromUtcTimeRequest, LocalTimeFromUtcTimeResponse>(request); return result; }
private DateTime GetUserLocalTime(DateTime utcTime, int timeZoneCode) { var request = new LocalTimeFromUtcTimeRequest { UtcTime = utcTime, TimeZoneCode = timeZoneCode }; var response = (LocalTimeFromUtcTimeResponse)_context.Service.Execute(request); return(response.LocalTime); }
public static Result RetrieveLocalTimeFromUTCTime(DateTime utcTime, int timeZoneCode, CubeBase Cube) { var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = timeZoneCode, UtcTime = utcTime.ToUniversalTime() }; Result result = Cube.XRMActions.Execute <LocalTimeFromUtcTimeRequest, LocalTimeFromUtcTimeResponse>(request); return(result); }
/// <summary> /// Retrieve <c>LocalTime</c> from <c>UtcTime</c> by <c>TimeZoneCode</c>. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.localtimefromutctimerequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="utcTime"> /// <see cref="DateTime"/> UtcTime /// </param> /// <param name="timezoneCode">You can use <see cref="TimezoneCode"/> data or directly provide Timezone Code.</param> /// <returns> /// <see cref="DateTime"/> LocalTime /// </returns> public DateTime GetLocalTimeFromUTCTime(DateTime utcTime, int timezoneCode) { LocalTimeFromUtcTimeRequest request = new LocalTimeFromUtcTimeRequest() { UtcTime = utcTime, TimeZoneCode = timezoneCode }; var serviceResponse = (LocalTimeFromUtcTimeResponse)this.OrganizationService.Execute(request); return(serviceResponse.LocalTime); }
/// <summary> /// Gets the local time from the UTC time. /// </summary> /// <param name="service"></param> /// <param name="userId">The id of the user to lookup the timezone code user settings</param> /// <param name="utcTime">The given UTC time to find the user's local time for. Defaults to DateTime.UtcNow</param> /// <param name="defaultTimeZoneCode">Default TimeZoneCode if the user has no TimeZoneCode defined. Defaults to EDT.</param> public static DateTime GetUserLocalTime(this IOrganizationService service, Guid userId, DateTime?utcTime, int defaultTimeZoneCode = 35) { var timeZoneCode = RetrieveUserSettingsTimeZoneCode(service, userId) ?? defaultTimeZoneCode; var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = timeZoneCode, UtcTime = utcTime ?? DateTime.UtcNow }; var response = (LocalTimeFromUtcTimeResponse)service.Execute(request); return(response.LocalTime); }
public static DateTime RetrieveLocalTimeFromUTCTime(IOrganizationService service, int timeZoneCode, DateTime utcTime) { var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = timeZoneCode, UtcTime = utcTime.ToUniversalTime() }; var response = (LocalTimeFromUtcTimeResponse)service.Execute(request); //Console.WriteLine(String.Concat("Calling LocalTimeFromUtcTimeRequest. UTC time: ", utcTime.ToString("MM/dd/yyyy HH:mm:ss"), ". Local time: ", response.LocalTime.ToString("MM/dd/yyyy HH:mm:ss"))); return(response.LocalTime); }
/// <summary> /// Retrieve <c>LocalTime</c> from <c>UtcTime</c> by <see cref="IOrganizationService"/> <c>Caller</c> 's settings. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.localtimefromutctimerequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="utcTime"> /// <see cref="DateTime"/> UtcTime /// </param> /// <returns> /// <see cref="DateTime"/> LocalTime /// </returns> public DateTime GetLocalTimeFromUTCTime(DateTime utcTime) { var userSettings = GetCurrentUsersSettings(null); LocalTimeFromUtcTimeRequest request = new LocalTimeFromUtcTimeRequest() { UtcTime = utcTime, TimeZoneCode = userSettings.Item2 }; var serviceResponse = (LocalTimeFromUtcTimeResponse)this.OrganizationService.Execute(request); return(serviceResponse.LocalTime); }
internal static 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); }
/// <summary> /// Convert Local datetime from UTC datetime /// </summary> /// <param name="utcDateTime"></param> /// <param name="timeZoneCode"></param> public DateTime LocalFromUtcDateTime(DateTime utcDateTime, int?timeZoneCode) { if (!timeZoneCode.HasValue) { return(utcDateTime); } LocalTimeFromUtcTimeRequest orgReq = new LocalTimeFromUtcTimeRequest { TimeZoneCode = timeZoneCode.Value, UtcTime = utcDateTime }; return(Execute <LocalTimeFromUtcTimeResponse>(orgReq).LocalTime); }
/// <summary> /// This method gets user local time (server time). /// </summary> /// <param name="coordinatedUniversalTime"> universal time </param> /// <param name="timeZoneCode"> time zone code </param> /// <param name="service"> organization service </param> /// <returns> date time </returns> public static DateTime GetUserLocalTime(DateTime coordinatedUniversalTime, int timeZoneCode, IOrganizationService service) { if (service != null) { var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = timeZoneCode, UtcTime = coordinatedUniversalTime }; var response = (LocalTimeFromUtcTimeResponse)service.Execute(request); return(response.LocalTime); } return(coordinatedUniversalTime); }
/// <summary> /// Retrieve <c>LocalTime</c> from <c>UtcTime</c> by specified <c>System User</c> 's settings. /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.localtimefromutctimerequest(v=crm.8).aspx /// </para> /// </summary> /// <param name="utcTime"> /// <see cref="DateTime"/> UtcTime /// </param> /// <param name="userId"><c>System User</c> Id</param> /// <returns> /// <see cref="DateTime"/> LocalTime /// </returns> public DateTime GetLocalTimeFromUTCTime(DateTime utcTime, Guid userId) { ExceptionThrow.IfGuidEmpty(userId, "userId"); var userSettings = GetCurrentUsersSettings(userId); LocalTimeFromUtcTimeRequest request = new LocalTimeFromUtcTimeRequest() { UtcTime = utcTime, TimeZoneCode = userSettings.Item2 }; var serviceResponse = (LocalTimeFromUtcTimeResponse)this.OrganizationService.Execute(request); return(serviceResponse.LocalTime); }
protected DateTime?RetrieveLocalTimeFromUTCTime(DateTime utcTime, int?_timeZoneCode) { if (!_timeZoneCode.HasValue) { return(null); } var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = _timeZoneCode.Value, UtcTime = utcTime.ToUniversalTime() }; var response = (LocalTimeFromUtcTimeResponse)ElevatedService.Execute(request); return(response.LocalTime); }
// call on CRM to convert a UTC time to the local time public static DateTime UTCToLocalTime(DateTime utcTime, int?timeZoneCode, ContextWrapper contextWrapper) { if (!timeZoneCode.HasValue) { return(utcTime); } var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = timeZoneCode.Value, UtcTime = DateTime.SpecifyKind(utcTime, DateTimeKind.Utc) }; var response = (LocalTimeFromUtcTimeResponse)contextWrapper.service.Execute(request); return(response.LocalTime); }
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() }; OrganizationResponse response = service.Execute(request); return((DateTime)response.Results["LocalTime"]); }
/// <summary> /// Retrive the local time from the UTC time. /// </summary> /// <param name="utcTime"></param> private void RetrieveLocalTimeFromUTCTime(DateTime utcTime) { if (!_timeZoneCode.HasValue) { return; } var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = _timeZoneCode.Value, UtcTime = utcTime.ToUniversalTime() }; var response = (LocalTimeFromUtcTimeResponse)_serviceProxy.Execute(request); Console.WriteLine(String.Concat("Calling LocalTimeFromUtcTimeRequest. UTC time: ", utcTime.ToString("MM/dd/yyyy HH:mm:ss"), ". Local time: ", response.LocalTime.ToString("MM/dd/yyyy HH:mm:ss"))); }
public static DateTime RetrieveLocalTimeFromUTCTimeStatic(DateTime utcTime, IOrganizationService service) { int?timeZoneCode = RetrieveCurrentUsersSettingsStatic(service); if (!timeZoneCode.HasValue) { throw new Exception("Can't find time zone code"); } var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = timeZoneCode.Value, UtcTime = utcTime.ToUniversalTime() }; var response = (LocalTimeFromUtcTimeResponse)service.Execute(request); return(response.LocalTime); //var utcTime = utcTime.ToString("MM/dd/yyyy HH:mm:ss"); //var localDateOnly = response.LocalTime.ToString("dd-MM-yyyy"); }
private DateTime?RetrieveLocalTimeFromUTCTime(IOrganizationService service, DateTime utcTime) { int?_timeZoneCode = RetrieveCurrentUsersTimeZoneSettings(service); if (!_timeZoneCode.HasValue) { return(null); } var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = _timeZoneCode.Value, UtcTime = utcTime.ToUniversalTime() }; var response = (LocalTimeFromUtcTimeResponse)service.Execute(request); return(response.LocalTime); }
public static DateTime RetrieveLocalTimeFromUtcTime(this DateTime utcTime, IOrganizationService service) { { var timeZone = RetrieveCurrentUsersTimeZoneSettings(service); if (!timeZone.HasValue) { return(DateTime.MinValue); } var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = timeZone.Value, UtcTime = utcTime.ToUniversalTime() }; var response = (LocalTimeFromUtcTimeResponse)service.Execute(request); return(response.LocalTime); } }
/// <summary> /// Extension method for universal date time zone it will need organization service and input /// </summary> /// <param name="coordinatedUniversalTime">Coordinated Universal Time</param> /// <param name="service">organization service</param> /// <returns>local user date time </returns> public static DateTime LocalDateTime(this DateTime coordinatedUniversalTime, IOrganizationService service) { int timeZoneCode; if (service != null) { timeZoneCode = GetUserTimeZoneCode(service); if (timeZoneCode != -1) { var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = timeZoneCode, UtcTime = coordinatedUniversalTime.ToUniversalTime() }; var response = (LocalTimeFromUtcTimeResponse)service.Execute(request); return(response.LocalTime); } } return(coordinatedUniversalTime); }
/// <summary> /// Retrive the local time from the UTC time. /// </summary> /// <param name="utcTime"></param> //<snippetLocalTimeFromUTCTime> private void RetrieveLocalTimeFromUTCTime(DateTime utcTime) { if (!_timeZoneCode.HasValue) return; var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = _timeZoneCode.Value, UtcTime = utcTime.ToUniversalTime() }; var response = (LocalTimeFromUtcTimeResponse)_serviceProxy.Execute(request); Console.WriteLine(String.Concat("Calling LocalTimeFromUtcTimeRequest. UTC time: ", utcTime.ToString("MM/dd/yyyy HH:mm:ss"), ". Local time: ", response.LocalTime.ToString("MM/dd/yyyy HH:mm:ss"))); }
/// <summary> /// Retrive the local time from the UTC time with IOrgService. /// </summary> public static DateTime RetrieveLocalTimeFromUtcTime(this IOrganizationService service, DateTime utcTime) { if (utcTime.Kind == DateTimeKind.Local) return utcTime; //throw new Exception("Вы хотели привести LocalTime to LocalTime"); var retrieveCurrentUsersSettings = service.RetrieveCurrentUsersSettings(); if (retrieveCurrentUsersSettings == null) throw new Exception("Не удалось определить настройки пользователя"); var request = new LocalTimeFromUtcTimeRequest { TimeZoneCode = retrieveCurrentUsersSettings.Value, UtcTime = utcTime.ToUniversalTime() }; var response = (LocalTimeFromUtcTimeResponse)service.Execute(request); var local = response.LocalTime; return local.Hour == 23 ? local.AddHours(1) : local; }
protected override void Execute(CodeActivityContext context) { var workflowContext = context.GetExtension <IWorkflowContext>(); var service = this.RetrieveOrganizationService(context); List <OptionSetValue> values = new List <OptionSetValue>() { this.Part1.Get <OptionSetValue>(context), this.Part2.Get <OptionSetValue>(context), this.Part3.Get <OptionSetValue>(context), this.Part4.Get <OptionSetValue>(context), this.Part5.Get <OptionSetValue>(context), this.Part6.Get <OptionSetValue>(context), this.Part7.Get <OptionSetValue>(context), this.Part8.Get <OptionSetValue>(context), this.Part9.Get <OptionSetValue>(context), this.Part10.Get <OptionSetValue>(context), this.Part11.Get <OptionSetValue>(context), this.Part12.Get <OptionSetValue>(context), this.Part13.Get <OptionSetValue>(context), this.Part14.Get <OptionSetValue>(context), this.Part15.Get <OptionSetValue>(context), this.Part16.Get <OptionSetValue>(context), this.Part17.Get <OptionSetValue>(context), this.Part18.Get <OptionSetValue>(context), this.Part19.Get <OptionSetValue>(context), this.Part20.Get <OptionSetValue>(context) }; values.RemoveAll(osv => osv == null || osv.Value == 222540025); TimeZoneSummary timeZone = StaticMethods.CalculateTimeZoneToUse(this.TimeZoneOption.Get(context), workflowContext, service); DateTime dateToModify = this.DateToModify.Get(context); if (dateToModify.Kind != DateTimeKind.Utc) { dateToModify = dateToModify.ToUniversalTime(); } LocalTimeFromUtcTimeRequest timeZoneChangeRequest = new LocalTimeFromUtcTimeRequest() { UtcTime = dateToModify, TimeZoneCode = timeZone.MicrosoftIndex }; LocalTimeFromUtcTimeResponse timeZoneResponse = service.Execute(timeZoneChangeRequest) as LocalTimeFromUtcTimeResponse; DateTime timeZoneSpecificDateTime = timeZoneResponse.LocalTime; StringBuilder sb = new StringBuilder(); foreach (OptionSetValue osv in values) { try { switch (osv.Value) { case 222540000: sb.Append(timeZoneSpecificDateTime.ToString("%h")); break; case 222540001: sb.Append(timeZoneSpecificDateTime.ToString("hh")); break; case 222540002: sb.Append(timeZoneSpecificDateTime.ToString("%H")); break; case 222540003: sb.Append(timeZoneSpecificDateTime.ToString("HH")); break; case 222540004: sb.Append(timeZoneSpecificDateTime.ToString("%m")); break; case 222540005: sb.Append(timeZoneSpecificDateTime.ToString("mm")); break; case 222540006: sb.Append(timeZoneSpecificDateTime.ToString("%d")); break; case 222540007: sb.Append(timeZoneSpecificDateTime.ToString("dd")); break; case 222540008: sb.Append(timeZoneSpecificDateTime.ToString("ddd")); break; case 222540009: sb.Append(timeZoneSpecificDateTime.ToString("dddd")); break; case 222540010: sb.Append(timeZoneSpecificDateTime.ToString("%M")); break; case 222540011: sb.Append(timeZoneSpecificDateTime.ToString("MM")); break; case 222540012: sb.Append(timeZoneSpecificDateTime.ToString("MMM")); break; case 222540013: sb.Append(timeZoneSpecificDateTime.ToString("MMMM")); break; case 222540014: sb.Append(timeZoneSpecificDateTime.ToString("%y")); break; case 222540015: sb.Append(timeZoneSpecificDateTime.ToString("yy")); break; case 222540016: sb.Append(timeZoneSpecificDateTime.ToString("yyyy")); break; case 222540017: sb.Append(timeZoneSpecificDateTime.ToString("%t")); break; case 222540018: sb.Append(timeZoneSpecificDateTime.ToString("tt")); break; case 222540019: sb.Append(" "); break; case 222540020: sb.Append(","); break; case 222540021: sb.Append("."); break; case 222540022: sb.Append(":"); break; case 222540023: sb.Append("/"); break; case 222540024: sb.Append(@"\"); break; case 222540026: sb.Append("-"); break; case 222540027: sb.Append(timeZone.Id); break; case 222540028: sb.Append(timeZone.FullName); break; default: break; } } catch { throw new Exception(osv.Value.ToString()); } } FormattedDate.Set(context, sb.ToString()); }
protected DataTable BuildDataTable(CodeActivityContext context, IWorkflowContext workflowContext, IOrganizationService service) { TimeZoneSummary timeZone = StaticMethods.CalculateTimeZoneToUse(this.TimeZoneOption.Get(context), workflowContext, service); DataTable table = new DataTable() { TableName = workflowContext.PrimaryEntityName }; table.Columns.AddRange(new DataColumn[] { new DataColumn("Date"), new DataColumn("User"), new DataColumn("Attribute"), new DataColumn("Old Value"), new DataColumn("New Value") }); DateTime oldestUpdate = DateTime.MinValue; if (this.Units != null && this.Number != null && this.Number.Get <int>(context) != 0) { OptionSetValue value = this.Units.Get <OptionSetValue>(context); if (value != null) { switch (value.Value) { case 222540000: oldestUpdate = DateTime.Now.AddYears(this.Number.Get <int>(context) * -1); break; case 222540001: oldestUpdate = DateTime.Now.AddMonths(this.Number.Get <int>(context) * -1); break; case 222540002: oldestUpdate = DateTime.Now.AddDays(this.Number.Get <int>(context) * -7); break; case 222540003: oldestUpdate = DateTime.Now.AddDays(this.Number.Get <int>(context) * -1); break; case 222540004: oldestUpdate = DateTime.Now.AddHours(this.Number.Get <int>(context) * -1); break; default: oldestUpdate = DateTime.Now.AddMinutes(this.Number.Get <int>(context) * -1); break; } } } RetrieveRecordChangeHistoryRequest request = new RetrieveRecordChangeHistoryRequest() { Target = new EntityReference(workflowContext.PrimaryEntityName, workflowContext.PrimaryEntityId), PagingInfo = new PagingInfo() { Count = 100, PageNumber = 1 } }; RetrieveRecordChangeHistoryResponse response = service.Execute(request) as RetrieveRecordChangeHistoryResponse; var detailsToInclude = response.AuditDetailCollection.AuditDetails .Where(ad => ad is AttributeAuditDetail && ad.AuditRecord.Contains("createdon") && ((DateTime)ad.AuditRecord["createdon"]) > oldestUpdate) .OrderByDescending(ad => ((DateTime)ad.AuditRecord["createdon"])) .ToList(); if (detailsToInclude.Any()) { Microsoft.Xrm.Sdk.Messages.RetrieveEntityRequest retrieveEntityRequest = new Microsoft.Xrm.Sdk.Messages.RetrieveEntityRequest() { EntityFilters = EntityFilters.Attributes, LogicalName = workflowContext.PrimaryEntityName }; Microsoft.Xrm.Sdk.Messages.RetrieveEntityResponse retrieveEntityResponse = service.Execute(retrieveEntityRequest) as Microsoft.Xrm.Sdk.Messages.RetrieveEntityResponse; EntityMetadata metadata = retrieveEntityResponse.EntityMetadata; foreach (var detail in detailsToInclude.Select(d => d as AttributeAuditDetail).Where(d => d.NewValue != null && d.OldValue != null)) { DateTime dateToModify = (DateTime)detail.AuditRecord["createdon"]; if (dateToModify.Kind != DateTimeKind.Utc) { dateToModify = dateToModify.ToUniversalTime(); } LocalTimeFromUtcTimeRequest timeZoneChangeRequest = new LocalTimeFromUtcTimeRequest() { UtcTime = dateToModify, TimeZoneCode = timeZone.MicrosoftIndex }; LocalTimeFromUtcTimeResponse timeZoneResponse = service.Execute(timeZoneChangeRequest) as LocalTimeFromUtcTimeResponse; DateTime timeZoneSpecificDateTime = timeZoneResponse.LocalTime; var details = detail.NewValue.Attributes.Keys.Union(detail.OldValue.Attributes.Keys) .Distinct() .Select(a => new { AttributeName = a, DisplayName = GetDisplayLabel(metadata, a) }) .OrderBy(a => a.DisplayName); foreach (var item in details) { DataRow newRow = table.NewRow(); newRow["User"] = GetDisplayValue(detail.AuditRecord, "userid"); newRow["Date"] = timeZoneSpecificDateTime.ToString("MM/dd/yyyy h:mm tt"); newRow["Attribute"] = item.DisplayName; newRow["Old Value"] = GetDisplayValue(detail.OldValue, item.AttributeName); newRow["New Value"] = GetDisplayValue(detail.NewValue, item.AttributeName); table.Rows.Add(newRow); } } } return(table); }