gpt4 book ai didi

c# - 如何将 DateTime 字段转换为 Dynamics CRM 中的日期?

转载 作者:行者123 更新时间:2023-11-30 23:13:29 25 4
gpt4 key购买 nike

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


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

Parameters Conversion rule: SpecificTimeZone TimeZoneCode: 35 AutoConvert: False Error details: The specified attribute isn’t a Date and Time attribute with the Date Only behavior: Entity: ccseq_clientstatus, Attribute: ccseq_prospectstatusdate Attributes Processed

Entity Definition


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);
}
}
}

最佳答案

根据文档:

When you execute the ConvertDateAndTimeBehaviorRequest message, a system job (asynchronous operation) is created to run the conversion request. The ConvertDateAndTimeBehaviorResponse.JobId attribute in the message response displays the ID of the system job that is created as a result of the conversion request. After the system job completes, check the job details (AsyncOperation.Message) to view conversion details or errors, if any.

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

关于c# - 如何将 DateTime 字段转换为 Dynamics CRM 中的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43596494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com