2016-07-26 20 views
0

Dynamics CRM SDKおよびC#を使用して結果を取得するコンソールアプリケーションを作成しようとしていますが、クエリから結果が得られないようです。私はサーバーに接続しているのがわかりましたが、フィルターを設定しなくても、私が試行しようとするQueryExpressionは何も返されないようです。私たちが対応する値を持っているというドキュメンテーションの例を使っても、私は空の手で終わります。CRM RetrieveMultipleResponseが結果を返さない

 CrmServiceClient crmSvc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["MyCRMServer"].ConnectionString); 
     Console.WriteLine(crmSvc.IsReady); 
     //Display the CRM version number and org name that you are connected to. 
     Console.WriteLine("Connected to CRM! (Version: {0}; Org: {1}", 
     crmSvc.ConnectedOrgVersion, crmSvc.ConnectedOrgUniqueName); 

     QueryExpression userSettingsQuery = new QueryExpression("contact"); 
     userSettingsQuery.ColumnSet.AllColumns = true; 
     var retrieveRequest = new RetrieveMultipleRequest() 
     { 
      Query = userSettingsQuery 
     }; 
     EntityCollection EntCol = (crmSvc.ExecuteCrmOrganizationRequest(retrieveRequest) as RetrieveMultipleResponse).EntityCollection; 
     foreach (var a in EntCol.Entities) 
     { 
      Console.WriteLine("Account name: {0} {1}", a.Attributes["firstname"], a.Attributes["lastname"]); 
     } 
     Console.Write(crmSvc.LastCrmError); 
     Console.Write(crmSvc.LastCrmException); 
     Console.ReadLine(); 

それはエラーを返していない、との接続のために真示しており、私はここからトラブルシューティングを開始する場所を見つけることができないよう:私のコードです。

答えて

1

あなたのコードは正常に動作するので、接続しているユーザーにcontactレコードを読み取る権限がないか、CRM組織にcontactレコードがありません。

また、サンプルをまとめようとしていることはわかっていますが、私は以下のコードをより単純なものにまとめました。

var crmSvc = new CrmServiceClient(<CONNECTION STRING>); 

    var contactQuery = new QueryExpression("contact") 
    { 
     ColumnSet = new ColumnSet("firstname", "lastname") 
    }; 
    var contacts = crmSvc.RetrieveMultiple(contactQuery).Entities; 
    foreach(var contact in contacts) 
    { 
     Console.WriteLine("Contact name: {0} {1}", contact.GetAttributeValue<String>("firstname"), contact.GetAttributeValue<String>("lastname")); 
    } 
+0

改善されたコードをお寄せいただきありがとうございます。これは、ちょっとしたコードをまとめたもので、これを動作させるためのさまざまな方法があります。私は過去に許可の問題があったので、私のCRM部署に相談しなければなりません。ありがとう。 – Greg2518

関連する問題