В настоящее время я получаю строку даты из CRM с помощью следующего
Entity dateDeliveryRequiredImage = (Entity)context.PostEntityImages["DeliveryRequired"];
Что действительно работает, однако по какой-то причине кажется, что я получаю время, когда я создаю файл CSV через следующую строку
dateDeliveryRequiredImage["requestdeliverby"].ToString()
Любая идея, откуда он получает время во-первых, поскольку нет места для ввода времени (и он говорит, что сейчас 11 вечера??)
А главное как от этого избавиться
Спасибо, Шон
Обновить
После вменения необходимого кода появились следующие ошибки
if (!timeZoneCode.HasValue)
return;
Требуется объект типа, конвертируемого в 'system.timeanddate'
var response = (LocalTimeFromUtcTimeResponse)_serviceProxy.Execute(request);
_serviceProxy не существует в текущем контексте
Мой код для службы выглядит следующим образом:
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
Однако ввод службы или контекста ничего не сделал
Наконец новое QueryExpression(UserSettings.EntityLogicalName)
С пользовательскими настройками, не существующими в текущем контексте
Обновление кода теперь работает
private DateTime RetrieveLocalTimeFromUTCTime(DateTime utcTime, IOrganizationService service)
{
int? timeZoneCode = RetrieveCurrentUsersSettings(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 int? RetrieveCurrentUsersSettings(IOrganizationService service)
{
var currentUserSettings = service.RetrieveMultiple(
new QueryExpression("usersettings")
{
ColumnSet = new ColumnSet("localeid", "timezonecode"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("systemuserid", ConditionOperator.EqualUserId)
}
}
}).Entities[0].ToEntity<Entity>();
return (int?)currentUserSettings.Attributes["timezonecode"];
}
Обратите внимание, что отличие от приведенного ниже кода заключается в следующих строках;
}).Entities[0].ToEntity<Entity>();
return (int?)currentUserSettings.Attributes["timezonecode"];