[英]How to convert DateTime field to Date in Dynamics CRM?
我正在按照本指南将 DateTime 字段更新为 Dynamics 中的 Date 字段。 当我在下面运行我的代码时,我没有收到错误,但我也没有看到我的日期字段有任何变化。
更新:根据 Pawel Gradecki 的回答和这篇文章,我检查了 AsyncOperationBase 表,在其中我发现了以下似乎与实体定义相矛盾的消息(如屏幕截图所示)。
参数转换规则:SpecificTimeZone TimeZoneCode:35 AutoConvert:False 错误详细信息:指定的属性不是具有“仅日期”行为的日期和时间属性:实体:ccseq_clientstatus,属性:ccseq_prospectstatusdate 处理的属性
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Messages;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace UpdateDateClientStatus1
{
class Program
{
static void Main(string[] args)
{
var cred = new System.ServiceModel.Description.ClientCredentials();
cred.Windows.ClientCredential.Domain = "DOMAIN";
cred.Windows.ClientCredential.UserName = "USERNAME";
cred.Windows.ClientCredential.Password = "PASSWORD";
OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(new Uri("url"), null, cred,null);
ConvertDateAndTimeBehaviorRequest request = new ConvertDateAndTimeBehaviorRequest()
{
Attributes = new EntityAttributeCollection()
{
// ccseq_clientstatus is the entity I am updating and ccseq_prospectstatusdate is the field I am updating
new KeyValuePair<string, StringCollection>("ccseq_clientstatus", new StringCollection()
{ "ccseq_prospectstatusdate" })
},
ConversionRule = DateTimeBehaviorConversionRule.SpecificTimeZone.Value,
TimeZoneCode = 035,// Time zone code for EST in CRM
AutoConvert = false // Conversion must be done using ConversionRule
};
// Execute the request
ConvertDateAndTimeBehaviorResponse response = (ConvertDateAndTimeBehaviorResponse)_serviceProxy.Execute(request);
}
}
}
根据文档:
当您执行 ConvertDateAndTimeBehaviorRequest 消息时,会创建一个系统作业(异步操作)来运行转换请求。 消息响应中的 ConvertDateAndTimeBehaviorResponse.JobId 属性显示因转换请求而创建的系统作业的 ID。 系统作业完成后,检查作业详细信息 (AsyncOperation.Message) 以查看转换详细信息或错误(如果有)。
所以首先,转换将在一段时间后完成,因为它是异步的,这就是你不会立即收到任何错误的原因。 其次,如果您想检查错误,您应该在给定 JobId 的 AsyncOperation(系统作业)中执行此操作,只需查找最新的系统作业或使用 SDK 检索此系统作业。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.