положить список контактов аккаунта в поле cc в email - PullRequest
0 голосов
/ 04 октября 2011

У меня есть задача создать плагин в crm 4, который должен 1. ввести в поле темы письма имя учетной записи, а затем 2. поместить список контактов учетной записи в поле cc электронной почты.,первое, что я сделал, и это сработало, но второе ... не так много ... я видел некоторые образцы, но ни один из них не был близок, чтобы помочь мне ... я хотел бы получить помощь и объяснить, как найтисписок контактов, которые принадлежат учетной записи, а затем поместите список в поле cc.вот начало ...:

namespace mail
{
public class Class1 : IPlugin
{
        public void Execute(IPluginExecutionContext context)
        {
            DynamicEntity entity = null;

            if (context.InputParameters.Properties.Contains("Target") &&
               context.InputParameters.Properties["Target"] is DynamicEntity)
            {
                entity = (DynamicEntity)context.InputParameters.Properties["Target"];

                if (entity.Name != EntityName.account.ToString())
                {
                    return;
                }
            }
            else
            {
                return;
            }

            try
            {
                // updating the subject of the email
                ICrmService service = context.CreateCrmService(true);
                account accountRecord = (account)service.Retrieve("account", ((Key)entity.Properties["accountid"]).Value, new ColumnSet(new string[] { "name" }));
                String str = String.Empty;
                str = accountRecord.name.ToString();
                DynamicEntity followup = new DynamicEntity();
                followup.Name = EntityName.email.ToString();

                followup.Properties = new PropertyCollection();
                followup.Properties.Add(new StringProperty("subject", str));

                //updating the CC of the email

                TargetCreateDynamic targetCreate = new TargetCreateDynamic();
                targetCreate.Entity = followup;

                CreateRequest create = new CreateRequest();
                create.Target = targetCreate;

                CreateResponse created = (CreateResponse)service.Execute(create);
            }
            catch
            {
                throw new InvalidPluginExecutionException(
                      "An error occurred in the AccountUpdateHandler plug-in.");
            }
        }
    }
}

1 Ответ

0 голосов
/ 25 октября 2011

Вы можете попробовать что-то вроде этого,

List<BusinessEntity> contactList = GetNeededContacts(crmService, sourceEntity);
email targetEmail = GetTargetEmail(crmService, emailid);            
foreach (DynamicEntity contact in contactList)
            {
                activityparty contActParty = new activityparty() { partyid = new Lookup("contact", contact.contactid.Value };
                List<activityparty> tmpList = targetEmail.cc.ToList();
                tmpList.Add(contActParty);
                targetEmail.cc = tmpList.ToArray();
            }
crmService.Update(targetEmail);

Вам нужно только разработать функцию, чтобы получить контакт, пользователя или учетную запись.

...