ID = [ID]的帐户不存在

时间:2019-11-28 10:31:00

标签: c# dynamics-crm dynamics-crm-online dynamics-crm-365

我正在尝试从Dynamics CRM检索自己的名字,但是在检索过程中我一直收到此消息。 (代码成功地通过WhoAmIRequest将我的用户ID返还给我) 具有ID = [ID]的System.ServiceModel.FaultException`1 [Microsoft.Xrm.Sdk.OrganizationServiceFault]帐户不存在。

   IOrganizationService oServiceProxy;
            try
            {
                //Create the Dynamics 365 Connection:
                CrmServiceClient oMSCRMConn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient("AuthType=Office365;Username=_username;Password=_password;URL=https://hrrevuat.crm4.dynamics.com/;");

                //Create the IOrganizationService:
                oServiceProxy = (IOrganizationService)oMSCRMConn.OrganizationWebProxyClient != null ?
                        (IOrganizationService)oMSCRMConn.OrganizationWebProxyClient :
                        (IOrganizationService)oMSCRMConn.OrganizationServiceProxy;
                if (oServiceProxy != null)
                {


                    //Get the current user ID:
                    Guid userid = ((WhoAmIResponse)oServiceProxy.Execute(new WhoAmIRequest())).UserId;



                    if (userid != Guid.Empty)
                    {
                        Console.WriteLine("Connection Successful!");
                        oServiceProxy.Retrieve("account", userid, new ColumnSet("name"));
                    }
                }
                else
                {
                    Console.WriteLine("Connection failed...");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error - " + ex.ToString());
            }

预先感谢!

1 个答案:

答案 0 :(得分:2)

从WhoAmIRequest获得的用户ID属于systemuser实体,而不是帐户实体。

oServiceProxy.Retrieve("systemuser", userid, new ColumnSet("fullname"));