[英]How can I retrieve all records (more than 5000 and/or more than 1 page) with the Dynamics 365 Web API in a Dynamics CRM organization with a C# plugin?
[英]Retrieve/fetch records from DYNAMICS 365 crm using C# code
問題1:
我是 MICROSOFT DYNAMICS CRM 365 的新手。我的 CRM 表很少,例如(帳戶,客戶)。我想從表帳戶中獲取所有數據。
以下是我的連接示例代碼:(不確定這是否正確,但收到我已連接到 CRM 的輸出消息)
public void ConnectToMSCRM(string UserName, string Password, string SoapOrgServiceUri)
{
try
{
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = UserName;
credentials.UserName.Password = Password;
Uri serviceUri = new Uri(SoapOrgServiceUri);
OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
proxy.EnableProxyTypes();
_services = (IOrganizationService)proxy;
Response.Write("Connected to CRM \n");
}
我需要在按鈕單擊事件上檢索所有數據。
輸出應該是: "select * from ABC"
;
如果可能,請建議如何使用給定的列名獲取記錄。
輸出應該是: "select * from ABC where ColumnName="test"
;
將所有實體列表提取到列表中
var allEntities = **GetEntities(_service);**
foreach (var Entity in allEntities)
{
ddlEntityName.Items.Add(Entity.LogicalName);
}
//單參數函數(oganizationservice作為參數)
//這將從 Microsoft Dynamics CRM 中獲取表/實體名稱,如 ACCOUNT、CONTACT
public Microsoft.Xrm.Sdk.Metadata.EntityMetadata[] GetEntities(IOrganizationService organizationService)
{
Dictionary<string, string> attributesData = new Dictionary<string, string>();
RetrieveAllEntitiesRequest metaDataRequest = new RetrieveAllEntitiesRequest();
RetrieveAllEntitiesResponse metaDataResponse = new RetrieveAllEntitiesResponse();
metaDataRequest.EntityFilters = EntityFilters.Entity;
XmlDictionaryReaderQuotas myReaderQuotas = new XmlDictionaryReaderQuotas();
myReaderQuotas.MaxNameTableCharCount = 2147483647;
// Execute the request.
metaDataResponse = (RetrieveAllEntitiesResponse)organizationService.Execute(metaDataRequest);
var entities = metaDataResponse.EntityMetadata;
return entities.OrderBy(x => x.LogicalName).ToArray();//to arrange in ascending order
}
查詢表達式呢?
這是您的查詢:
Select * from ABC where ColumnName="test";
這是QueryExpression
:
QueryExpression query = new QueryExpression()
{
EntityName = Contact.EntityLogicalName,
ColumnSet = new ColumnSet("address1_telephone1"),
};
執行查詢,這是如何:
DataCollection<Entity> entityCollection = _services.RetrieveMultiple(query).Entities;
// Display the results.
foreach (Contact entity in entityCollection)
{
Console.WriteLine("my test: {0}", entity.address1_telephone1);
}
問候
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.