В настоящее время я изучаю 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
Обновление полей в контакте ⇐ C#
Место общения программистов C#
1714947005
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.");
}
}
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78393372/updating-fields-in-a-contact[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия