Possible to insert post into dynamics CRM social pane posts using XRM SDK?

63 views Asked by At

I'm using Microsoft.Xrm.Sdk to interact with Dynamics CRM On-Premise. What I want to do is insert a post into Lead entity social pane posts via API.

enter image description here

What I did is as below:

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);

Is it possible to insert posts using XRM SDK?

1

There are 1 answers

0
jasonscript On BEST ANSWER

Yes, this is possible! The schema name that you're looking for is post

To create a new post record should be straightforward as you already have your connection:

var crm = new OrganizationServiceProxy(...);
var entity = await crm.RetrieveAsync("lead", new Guid(model.Id), columns, CancellationToken.None);

Continuing this, you can create your new post record:

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);

The source column refers to whether the post was created automatically or manually. See Microsoft Documentation.

and then save the record

crm.Create(postData);