AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 13.11.2013, 16:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
mscrmblog: CRM 2011 – Set the Email regarding field to the contact in the recipient address
Источник: http://mscrmblog.net/2013/11/13/crm-...pient-address/
==============

Scenario: An email gets sent out and copies in the Queue Email Address. The Email router picks up the email and sticks it in the queue. Client wanted to automatically track the the email against the contact in the recipient address automatically (note: all contacts getting emails sent to already exist as contacts in the system). There was no way to do this using the workflow engine since the Recipient field and the Regarding field are two different types (partylist vs entityreference). I created a  plug-in to do the job. Register the plugin on pre-operation and this should do the job.



using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WC.CRM { public class WCEmailPlugin : IPlugin { public void Execute(IServiceProvider serviceProvider) { var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); if (context.Depth > 1) return; var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); var service = serviceFactory.CreateOrganizationService(context.UserId); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { // Obtain the target entity from the input parmameters. var entity = (Entity)context.InputParameters["Target"]; try { if (entity.Attributes.Contains("to") && entity.Attributes.Contains("subject")) { var recipients = entity.GetAttributeValue("to"); foreach (var party in recipients.Entities) { var partyName = party.GetAttributeValue("partyid").Name; var partyId = party.GetAttributeValue("partyid").Id; var partyType = party.GetAttributeValue("partyid").LogicalName; if (partyType == "contact") { var contactRec = service.Retrieve("contact", partyId, new ColumnSet(true)); entity["regardingobjectid"] = new EntityReference() { LogicalName = "contact", Id = partyId, Name = contactRec.GetAttributeValue("fullname") }; } } } } catch (Exception ex) { throw new InvalidPluginExecutionException("Error: " + ex.Message); } } } } }







Источник: http://mscrmblog.net/2013/11/13/crm-...pient-address/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 15 Blog bot Dynamics CRM: Blogs 1 10.02.2016 10:26
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 14 Blog bot Dynamics CRM: Blogs 0 12.07.2013 07:13
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 13 Blog bot Dynamics CRM: Blogs 0 27.03.2013 22:12
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 12 Blog bot Dynamics CRM: Blogs 0 30.01.2013 01:11
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 10 Blog bot Dynamics CRM: Blogs 0 17.08.2012 03:27
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 17:37.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.