gpt4 book ai didi

c# - 微软客户关系管理 : How to enable/disable Systemuser without deprecated SetStateRequest

转载 作者:太空狗 更新时间:2023-10-29 23:20:19 25 4
gpt4 key购买 nike

要使用 C# 代码禁用 Dynamics CRM 2016 用户,当前使用的是 SetStateRequest。例子:

var requestToDisableUser = new SetStateRequest()
{
EntityMoniker = new EntityReference("systemuser", userGuid),
State = new OptionSetValue(1),
Status = new OptionSetValue(-1)
};
organizationService.Execute(requestToDisableUser);

但是,根据 Microsoft SetStateRequest已弃用,应使用 Update 替换

但是当我尝试使用更新来禁用用户时
示例:

var userToDisable = new Entity("systemuser", userGuid)
{
["statecode"] = new OptionSetValue(1),
["statuscode"] = new OptionSetValue(-1)
};
service.Update(userToDisable);

然后它引发错误:

Unhandled Exception: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: 'systemuser' entity doesn't contain attribute with Name = 'statecode'.

这是真的,因为 systemuser 实体没有状态代码。
systemuser 实体有一个 IsDisabled 属性,但那个是只读的。

那么如何在不使用 SetStateRequest 的情况下禁用/启用用户?

最佳答案

我认为这是不可能的,除非有人证明它是。为了支持我的观点:最新的 SDK (8.2.1.1; 4/6/2017) 仍然给出了 SDK\SampleCode\CS\BusinessDataModel\UsersAndRoles\DisableOREnableUser.cs< 中的 SetStateRequest 示例。因此,它应该是推荐的方法,不管它在文档的另一部分中被标记为已弃用。

您可能会在 MS 支持下发起事件,或在 Connect 上提出建议;但根据我的经验,他们不太关心是否有解决方法。

关于c# - 微软客户关系管理 : How to enable/disable Systemuser without deprecated SetStateRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45997832/

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