【问题标题】:How to convert DateTime field to Date in Dynamics CRM?如何在 Dynamics CRM 中将 DateTime 字段转换为 Date?
【发布时间】:2017-04-24 19:45:14
【问题描述】:

我正在按照 this 指南将 DateTime 字段更新为 Dynamics 中的 Date 字段。当我在下面运行我的代码时,我没有收到错误,但我也没有看到我的日期字段有任何更改。


更新:根据 Pawel Gradecki 的回答和 this 文章,我检查了 AsyncOperationBase 表,发现以下消息似乎与实体定义相矛盾(如屏幕截图所示)。

参数转换规则:SpecificTimeZone TimeZoneCode:35 自动转换:错误错误详细信息:指定的属性不是日期 和具有仅日期行为的时间属性:实体: 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);
    }
}
}

【问题讨论】:

  • 原来是在我做出更改后忘记发布我的更改

标签: c# datetime dynamics-crm


【解决方案1】:

根据文档:

当您执行 ConvertDateAndTimeBehaviorRequest 消息时,一个 创建系统作业(异步操作)以运行转换 要求。中的 ConvertDateAndTimeBehaviorResponse.JobId 属性 消息响应显示创建为的系统作业的 ID 转换请求的结果。系统作业完成后, 检查作业详细信息 (AsyncOperation.Message) 以查看转换 详细信息或错误(如果有)。

首先,转换将在一段时间后完成,因为它是异步的,这就是为什么您不会立即收到任何错误的原因。其次,如果要检查错误,应该在给定 JobId 的 AsyncOperation (System Job) 中执行此操作,只需查找最新的 System Jobs 或使用 SDK 检索此系统 Job。

【讨论】:

  • 我根据您的回答更新了我的问题。如果您有任何其他意见,我将不胜感激
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-21
  • 1970-01-01
相关资源
最近更新 更多