Hi, i have requirement to create email in CRM using C#.
The following is a piece of code used to get the list of recipients.
for (int iusr = 0; iusr < dtableUserQuality.Rows.Count; iusr ) { systemuserid = Guid.Empty; systemuserid = new Guid(dtableUserQuality.Rows[iusr][0].ToString()); QueryExpression to_query = new QueryExpression("systemuser"); to_query.Criteria = new FilterExpression(); to_query.Criteria.AddCondition("systemuserid", ConditionOperator.Equal, systemuserid); to_query.ColumnSet = new ColumnSet(true); EntityCollection to_colect_email = _service.RetrieveMultiple(to_query); toUserParty.EntityName = "systemuser"; foreach (Entity to_ent_email in to_colect_email.Entities) { string fullname = to_ent_email.GetAttributeValue("fullname"); Entity fromParty = new Entity("activityparty"); EntityReference userParty = new EntityReference("systemuser", to_ent_email.Id); fromParty.Attributes.Add("partyid", userParty); toUserParty.Entities.Add(fromParty); } } if (toUserParty.Entities.Count > 0) { email.Attributes.Add("to", toUserParty); }
The email created succesfully, however the code allowed duplicate user exist in the recepients list.
how to prevent users already in the recipient list from being duplicated.
Thanks
Hi david, using your second idea, finally i can prevent duplicate recepient. Thanks
Its seems dtableUserQuality. table has duplicate entry.
Hi Gouthan, i found that after using your code the results didn't change.
Hi ,
Try with this -
for (int iusr = 0; iusr < dtableUserQuality.Rows.Count; iusr ) { systemuserid = Guid.Empty; systemuserid = new Guid(dtableUserQuality.Rows[iusr][0].ToString()); Entity to_colect_email = _service.Retrieve("systemuser", systemuserid, new ColumnSet(true)); //Use retrieve as you are using Guid in the filter operation , and put column name which you need toUserParty.EntityName = "systemuser"; string fullname = to_colect_email.GetAttributeValue("fullname"); // I dont see any reason for this code Entity fromParty = new Entity("activityparty"); EntityReference userParty = new EntityReference("systemuser", to_colect_email.Id); fromParty.Attributes.Add("partyid", userParty); toUserParty.Entities.Add(fromParty); } if (toUserParty.Entities.Count > 0) { email.Attributes.Add("to", toUserParty); }
Some sample code for your reference at docs.microsoft.com/.../hh210213(v=crm.8)
There are 2 ways you could do this:
Daivat Vartak (v-9d...
225
Super User 2025 Season 1
Eugen Podkorytov
106
Muhammad Shahzad Sh...
106
Most Valuable Professional