я только только его пишу

добавлю проверки заполнености полей
а сам код вот:
X++:
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Client;
namespace Microsoft.Crm.Sdk.Samples
{
public class updatePhonecall : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
// Verify that the target entity represents an account.
// If not, this plug-in was not registered correctly.
if (entity.LogicalName != "phonecall") { return; }
// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
if (context.Depth == 1)
{
Entity phonecall = service.Retrieve("phonecall", entity.Id, new ColumnSet(true));
if (phonecall.Attributes.Contains("regardingobjectid"))
{
EntityReference regarding = (EntityReference)phonecall.Attributes["regardingobjectid"];
if (regarding.LogicalName == "lead")
{
Entity lead = service.Retrieve("lead", regarding.Id, new ColumnSet(true));
EntityReference companyname = (EntityReference)lead.Attributes["new_companyname"];
Entity account = service.Retrieve("account", companyname.Id, new ColumnSet(true));
string name = account.Attributes["name"].ToString();
phonecall.Attributes.Add("new_nameofaccount", name);
service.Update(phonecall);
return;
}
if (regarding.LogicalName == "account")
{
Entity account = service.Retrieve("account", regarding.Id, new ColumnSet(true));
string name = account.Attributes["name"].ToString();
phonecall.Attributes.Add("new_nameofaccount", name);
service.Update(phonecall);
return;
}
if (regarding.LogicalName == "campaignactivity")
{
string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='account'>
<attribute name='name' />
<attribute name='new_footnote' />
<attribute name='new_typeofownership' />
<attribute name='address1_city' />
<attribute name='new_inn' />
<attribute name='ownerid' />
<attribute name='emailaddress1' />
<attribute name='telephone1' />
<attribute name='address1_stateorprovince' />
<attribute name='accountid' />
<order attribute='name' descending='false' />
<filter type='and'>
<condition attribute='statuscode' operator='eq' value='1' />
</filter>
<link-entity name='activityparty' from='activityid' to='activityid' alias='aa'>
</link-entity>
</entity>
</fetch>";
Entity result = service.RetrieveMultiple(new FetchExpression(fetchXml)).Entities.FirstOrDefault();
Entity account = service.Retrieve("account", result.Id, new ColumnSet(true));
string name = account.Attributes["name"].ToString();
phonecall.Attributes.Add("new_nameofaccount", name);
service.Update(phonecall);
}
}
}
}
}
}
}
все получаю, кроме значения из поля получатель.
Понимаю что нужны проверки и исключения ... в последствии добавлю, чтоб плагин отрабатывал без ошибок с первого раза.
P.S. я его подключаю на два сообщения: Create и Update. на pre событие