我正在使用 Microsoft.Xrm.Sdk 与 Dynamics CRM On-Premise 进行交互。我想要做的是通过 API 将帖子插入到 Lead 实体社交窗格帖子中。
我所做的如下:
var _crmUrl = _configuration.GetSection("Crm:Url").Value;
var _organizationName = _configuration.GetSection("Crm:Org").Value;
var clientCredentials = new System.ServiceModel.Description.ClientCredentials();
clientCredentials.Windows.ClientCredential.UserName = _configuration.GetSection("Crm:user").Value;
clientCredentials.Windows.ClientCredential.Password = _configuration.GetSection("Crm:pass").Value;
var crm = new OrganizationServiceProxy($"{_crmUrl}{_organizationName}", clientCredentials.Windows.ClientCredential);
Microsoft.Xrm.Sdk.Query.ColumnSet columns = new Microsoft.Xrm.Sdk.Query.ColumnSet() { AllColumns = true };
var entity = await crm.RetrieveAsync("lead", new Guid(model.Id), columns, CancellationToken.None);
// INSERT POST TO entity
await crm.UpdateAsync(entity, CancellationToken.None);
可以使用XRM SDK插入帖子吗?
post
创建新的
post
记录应该很简单,因为您已经拥有连接:
var crm = new OrganizationServiceProxy(...);
var entity = await crm.RetrieveAsync("lead", new Guid(model.Id), columns, CancellationToken.None);
继续此操作,您可以创建新的
post
记录:
var postData = new Entity("post");
postData["text"] = "This is an automatic post from a plugin!";
postData["source"] = 1;
postData["regardingobjectid"] = new EntityReference("lead", entity.Id);
source
列指的是post
是自动创建还是手动创建。请参阅 Microsoft 文档。
然后保存记录
crm.Create(postData);