データを取得するために XRM ツールを使用する

Microsoft Dataverse でデータを取得するには、CrmServiceClientServiceClient クラスには複数のメソッドが用意されています。 次の例は ID または FetchXML クエリでレコードを取得する方法を示します。

GetEntityDataById

このメソッドは、指定された ID でテーブルを検索します。 このサンプルでは、フィールド リスト値に null を指定して、指定したテーブル レコード (アカウント) のすべての列を取り込み、取得したアカウント レコードの名前を表示します。

ServiceClient クラスを使用する場合、次でメソッドを見つけることができます: QueryExtensions.GetEntityDataById

CrmServiceClient svc = new CrmServiceClient(connectionstring); 
// ServiceClient svc = new ServiceClient(connectionstring); 
  
// Verify that you are connected.  
if (svc != null && svc.IsReady)  
{  
    Dictionary<string, object> data = svc.GetEntityDataById("account", <Account_ID>, null);  
    foreach (var pair in data)  
    {  
        if (pair.Key == "name")  
        {  
            Console.WriteLine("Name of the account is {0}", pair.Value);  
        }  
    }  
}  
else  
{  
    // Display the last error.  
    Console.WriteLine("An error occurred: {0}", svc.LastCrmError);  
  
    // Display the last exception message if any.  
    Console.WriteLine(svc.LastCrmException.Message);  
    Console.WriteLine(svc.LastCrmException.Source);  
    Console.WriteLine(svc.LastCrmException.StackTrace);  
  
    return;  
}  
  

GetEntityDataByFetchSearchEC

このメソッドは、指定された FetchXML クエリに基づいてテーブルを検索します。 このサンプルでは、システムのすべての取引先企業レコードの数を取得および表示します。

ServiceClient クラスを使用する場合、次でクエリ メソッドを見つけることができます: QueryExtensions.GetEntityDataByFetchSearch

CrmServiceClient svc = new CrmServiceClient(connectionstring);
// ServiceClient svc = new ServiceClient(connectionstring);  
  
// Verify that you are connected.  
if (svc != null && svc.IsReady)  
{   
    string fetchXML =   
        @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' returntotalrecordcount='true' >  
            <entity name='account'>  
              <attribute name='accountid' />  
            </entity>  
        </fetch>";  
    var queryResult = crmSvc.GetEntityDataByFetchSearchEC(fetchXML);  
    if (queryResult != null)  
    {  
        Console.WriteLine(String.Format("Account Records Count : {0}", queryResult.TotalRecordCount));  
    }  
}  
else  
{  
    // Display the last error.  
    Console.WriteLine("An error occurred: {0}", svc.LastCrmError);  
  
    // Display the last exception message if any.  
    Console.WriteLine(svc.LastCrmException.Message);  
    Console.WriteLine(svc.LastCrmException.Source);  
    Console.WriteLine(svc.LastCrmException.StackTrace);  
  
    return;  
}  

参照

XRM ツールを使用して Dataverse に接続する
XRM ツール API を使用して Dataverse でアクションを実行

注意

ドキュメントの言語設定についてお聞かせください。 簡単な調査を行います。 (この調査は英語です)

この調査には約 7 分かかります。 個人データは収集されません (プライバシー ステートメント)。