MS CRM 4.0 CrmService - 关闭任务

发布于 2024-08-08 14:49:37 字数 2414 浏览 9 评论 0原文

我正在尝试弄清楚如何使用 CrmService 来关闭 MS CRM 4.0 中的任务

我尝试使用 SetStateTaskRequest 将任务的状态和状态设置为 TaskState.Completed 和 5。我还尝试了 TaskState.Completed 和 -1,但也没有骰子。

不管怎样,我在 CrmService.Execute 尝试中只会收到有用的“服务器无法处理请求”异常。

我可以随意创建和更新任务。但我似乎无法将它们设置为完成。真令人沮丧。

我注意到我只能通过“关闭任务”操作将 CRM 中的任务状态设置为“已完成”。我想知道是否需要进行单独的 CrmService 调用来执行“关闭任务”操作,而不是通过 CrmService.Execute 方法。

哦:我正在以完全权限登录 CrmService。所以我看不出这是任务项的权限问题。

我想不出还有什么可能导致这个问题。任何建议,甚至只是正确方向的一点,都将非常感激。

第一次编辑:

感谢grega ganswer 让我检查异常的详细信息字段。

我现在有更详细的异常消息。 XML 形式:

<error>
    <code>0x80040203</code>
    <description>Invalid format of input XML for request SetStateTask: required field 'EntityId' is missing.</description>
    <type>Platform</type>
</error>

这很奇怪 - 考虑我的代码(几乎与 greg g 的相同:

SetStateTaskRequest request = new SetStateTaskRequest();
request.EntityID = gTaskId;
request.TaskState = TaskState.Completed;

// ETaskStatusCode is an enumeration of the status codes taken from the StringMap in CRM.
//
// ETaskStatusCode.Completed = 5 - I can confirm this is the accurate status value for a Closed Task.
//
// Also, I have attempted this code with -1, which the documentation claims should cause the status
// to automatically be set to the default status for the supplied state. No change there.
request.TaskStatus = (int)ETaskStatusCode.Completed;            

SetStateTaskResponse response = CRMManager.CrmService.Execute(request) as SetStateTaskResponse;

另外,只是为了确认我有正确的状态代码(并且还分享一些我在处理 MS CRM 时发现非常有用的东西),这里是我用来确定实体状态值的 SQL

SELECT
    MSE.ObjectTypeCode,
    MSE.PhysicalName,
    SM.AttributeName,
    SM.Value,
    SM.AttributeValue
FROM MetadataSchema.Entity MSE
    INNER JOIN StringMap SM on MSE.ObjectTypeCode = SM.ObjectTypeCode
ORDER BY MSE.PhysicalName, SM.AttributeName, SM.AttributeValue  

我可以从 MS CRM Web 界面确认与“已完成”任务关联的“状态”值也名为“已完成”。我可以从上面的 SQL 确认该状态的值,对于任务,是 5 - 这是从我的 Enum 传入的值,

我还可以确认 gTaskId 被设置为引用实际存在的任务的有效 Guid,并且在尝试关闭时处于打开状态。

有什么更好奇和更好奇的想法吗?

I'm trying to work out how to use the CrmService to close a Task in MS CRM 4.0

I've tried to use the SetStateTaskRequest to set a Task's state and status to TaskState.Completed and 5. I also tried TaskState.Completed and -1, but no dice there either.

Either way, I only receive the ever-helpful "Server was unable to process request" exception on the CrmService.Execute attempt.

I can create and update Tasks as freely as I please. But I can't seem to set them to completed. It's frustrating.

I noticed that I can only set the state of a Task to Completed in CRM through the Close Task action. I was wondering if there is a separate CrmService call that I need to make to perform the Close Task action, rather than going through the CrmService.Execute method.

Oh: I'm logging into the CrmService with full permissions. So I can't see that it would be a permissions issue on the task item.

I can't think what else could be causing this issue. Any advice or even just a point in the right direction would be very much appreciated.

FIRST EDIT:

Thanks to grega g's answer for getting me to check the Detail field of the exception.

I now have a more detailed exception message. In XML Form:

<error>
    <code>0x80040203</code>
    <description>Invalid format of input XML for request SetStateTask: required field 'EntityId' is missing.</description>
    <type>Platform</type>
</error>

Which is bizarre - consider my code (almost identical to greg g's:

SetStateTaskRequest request = new SetStateTaskRequest();
request.EntityID = gTaskId;
request.TaskState = TaskState.Completed;

// ETaskStatusCode is an enumeration of the status codes taken from the StringMap in CRM.
//
// ETaskStatusCode.Completed = 5 - I can confirm this is the accurate status value for a Closed Task.
//
// Also, I have attempted this code with -1, which the documentation claims should cause the status
// to automatically be set to the default status for the supplied state. No change there.
request.TaskStatus = (int)ETaskStatusCode.Completed;            

SetStateTaskResponse response = CRMManager.CrmService.Execute(request) as SetStateTaskResponse;

Also, just to confirm that I have the right status code (and also share something I've found very useful when dealing with MS CRM), here's the SQL I use to determine the values for entity statuses.

SELECT
    MSE.ObjectTypeCode,
    MSE.PhysicalName,
    SM.AttributeName,
    SM.Value,
    SM.AttributeValue
FROM MetadataSchema.Entity MSE
    INNER JOIN StringMap SM on MSE.ObjectTypeCode = SM.ObjectTypeCode
ORDER BY MSE.PhysicalName, SM.AttributeName, SM.AttributeValue  

I can confirm from the MS CRM web interface that the Status value that is associated with a Completed task is also named Completed. I can confirm from the SQL above that the value of this status, for a Task, is 5 - this is the value passed in from my Enum.

I can also confirm that gTaskId is being set to a valid Guid that references a Task that actually does exist, and is open at the time the close is attempted.

Curiouser and curiouser. Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风铃鹿 2024-08-15 14:49:37

使用SetStateTaskRequest类。

SetStateTaskRequest task2Close = new SetStateTaskRequest();
task2Close.EntityId = <taskGuid>
task2Close.TaskState = TaskState.Completed;
task2Close.TaskStatus = <some value>

try
{
    SetStateTaskResponse r = (SetStateTaskResponse) crmSvc.Execute(task2Close);
}
catch (SoapException e)
{
   //Use e.Details for more info than "server was unable ..."
}

这段代码应该可以工作(或者让你看看为什么会发生错误)

Use SetStateTaskRequest class.

SetStateTaskRequest task2Close = new SetStateTaskRequest();
task2Close.EntityId = <taskGuid>
task2Close.TaskState = TaskState.Completed;
task2Close.TaskStatus = <some value>

try
{
    SetStateTaskResponse r = (SetStateTaskResponse) crmSvc.Execute(task2Close);
}
catch (SoapException e)
{
   //Use e.Details for more info than "server was unable ..."
}

This code should work (or let you see why error occurs)

腹黑女流氓 2024-08-15 14:49:37

您确定在尝试关闭任务时传递的状态值对于已完成状态有效吗?不同的状态码仅与其对应的状态码有效。您可以添加源代码和状态实体自定义的一部分吗?

Are you sure that when you are trying to close task you're passing status value which is valid for Completed state? Different status codes are only valid with their corresponding state codes. Can you add your source code and a portion of your state entity customization?

烟花肆意 2024-08-15 14:49:37

找到了!

好的 - 仔细检查上面的代码和错误消息,我的 CrmService 包含属性 EntityID - 但例外是属性 EntityId 丢失。

不知何故,我的 CrmService 将其 EntityId 属性重命名为 EntityID。

重命名属性解决了问题。我仍然不知道这件事最初是如何发生的。

为了安全起见,我将重新生成一个新的服务代理,以确保我的属性正确命名。

查看代码,似乎有人对“Id”进行了查找和替换,并将其转换为“ID”——顺便说一句,这也是我工作场所中表示主键的属性字段的命名约定。

再次感谢 grega g 指出 Detail 属性包含我需要的额外信息。

Found it!

Okay - reviewing my code above and the error message closely, my CrmService contained the property EntityID - but the exception was that the property EntityId was missing.

Somehow, my CrmService had its EntityId property renamed to EntityID.

Renaming the property fixed the problem. I still have no idea how that happened in the first place.

To be safe, I'll regenerate a new Service proxy to make sure that my properties are correctly named.

Looking through the code, it seems that someone did a find-and-replace on 'Id' and turned it into 'ID' - which incidentally is the naming convention in my workplace for Property fields that represent primary keys.

Thanks again to grega g for pointing out that the Detail property had the extra information I needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文