Quantcast
Channel: CRM Development 論壇
Viewing all articles
Browse latest Browse all 10280

Cannot alter email "to" field on plugin pre-create

$
0
0

Hello,

I'm trying to alter the "to" party field of an email entity, via a pre-create plugin. I manage to change the subject, for example, but the "to" won't alter. Here's the code:

Email email = entity.ToEntity<Email>();

                    if (email.Attributes.ContainsKey("to"))
                    {
                        EntityCollection recipients = email.GetAttributeValue<EntityCollection>("to");
                        EntityCollection finalRecipients = new EntityCollection();

                        for (int i = 0; i < recipients.Entities.Count; i++)
                        {
                            #region Activity Party Information
                            Entity party = recipients.Entities[i];
                            string partyEntityName = party.GetAttributeValue<EntityReference>("partyid").LogicalName.ToLower();
                            string partyName = party.GetAttributeValue<EntityReference>("partyid").Name;
                            Guid partyId = party.GetAttributeValue<EntityReference>("partyid").Id;
                            #endregion

                            #region Replace Entry
                            if (partyEntityName == "account")
                            {
                                // Get final replacer
                                Guid replacerId = GetAccountReplacer(service, partyId);

                                if (replacerId != Guid.Empty && replacerId != partyId)
                                {
                                    Entity account = service.Retrieve("account", replacerId, new ColumnSet(true));

                                    if (account != null)
                                    {
                                        Entity actParty = new Entity("activityparty");
                                        actParty["partyid"] = new EntityReference("account", replacerId);
                                        actParty["addressused"] = account.Attributes["emailaddress1"].ToString();

                                        if (!finalRecipients.Entities.Contains(actParty))
                                            finalRecipients.Entities.Add(actParty);
                                    }
                                }
                                else
                                {
                                    if (!finalRecipients.Entities.Contains(party))
                                        finalRecipients.Entities.Add(party);
                                }
                            }
                            else if (partyEntityName == "systemuser")
                            {
                            }
                            #endregion
                        }

                        if (email.Attributes.ContainsKey("to"))
                            email.Attributes["to"] = finalRecipients;
                        else
                            email.Attributes.Add("to", finalRecipients);

                        if (email.Attributes.ContainsKey("subject"))
                            email.Attributes["subject"] = "subiect modificat din plugin";
                        else
                            email.Attributes.Add("subject", "subiect modificat din plugin");
                    }


Am I doing anything wrong? No errors thrown in the above code...

Thanks.


Cornel Croitoriu - Senior Software Developer

If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

Biz-Forward.comCroitoriu.NET


Viewing all articles
Browse latest Browse all 10280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>