Обновление полей в контактеC#

Место общения программистов C#
Ответить
Anonymous
 Обновление полей в контакте

Сообщение Anonymous »

В настоящее время я изучаю Dynamics и пытаюсь обновить поле «Предпочитаемый метод контакта» контакта, используя только поля «адрес электронной почты1» и «телефон1». Когда я выбираю один из этих вариантов и заполняю соответствующее поле, контакт должен обновиться. Однако я получаю сообщение об исключении только тогда, когда пытаюсь обновить контакт, в противном случае сообщение об исключении должно появиться. Можете ли вы помочь мне понять, что может быть причиной проблемы?
Я написал следующий код, взяв значение из поля, которое я обновляю в методе предпочтительного контакта, и не знаю. где я делаю не так:
using System;
using Microsoft.Xrm.Sdk;

namespace BasicPluginTwo
{
public class ContactUpdatePlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
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 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 entity represents a contact.
if (entity.LogicalName != "contact") return;

// Check if Preferred Contact Method, Email or Phone fields
int preferredContactMethodOption = entity.GetAttributeValue("preferredcontactmethodcode").Value;
string email = entity.Contains("emailaddress1") ? entity.GetAttributeValue("emailaddress1") : string.Empty;
string phone = entity.Contains("telephone1") ? entity.GetAttributeValue("telephone1") : string.Empty;

// Validate fields based on Preferred Contact Method
if ((preferredContactMethodOption == 2 && string.IsNullOrEmpty(email)) || (preferredContactMethodOption == 3 && string.IsNullOrEmpty(phone)))
{
throw new InvalidPluginExecutionException("Preferred Contact Method requires a corresponding non-empty contact detail.");
}
}
}
}
}


Подробнее здесь: https://stackoverflow.com/questions/783 ... -a-contact
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»