Answered by:
How to validate CC list in Email Entity (Activity) CRM 2011

Question
-
Hi,
In CRM 2011 Email entity (Activity) when trying to reply all in CC duplicate contacts and users (same contacts and users) are fetching.
I want to remove these duplicate contacts and users from CC list while replying in CRM.
Is there any possibility to achieve this using JavaScript or Plugins?
Please let me know if anybody having any ideas.
Yadav
Friday, May 8, 2015 2:22 PM
Answers
-
Mark this as Answer if this helps you.
Madhu M.
- Marked as answer by Yadav MSCRM Technical Consultant Tuesday, May 26, 2015 10:41 AM
Monday, May 11, 2015 12:52 AM
All replies
-
Below is the snippet that I have written couple of years back to avoid duplicate values for TO and CC Recipients in CRM 2011. Additionally I am assigning values in BCC as well. Trim the unnecessary content.
// JavaScript source code
function emailonload() {if (Xrm.Page.ui.getFormType() == 1 || Xrm.Page.ui.getFormType() == 2) {
var Regarding = Xrm.Page.getAttribute("regardingobjectid").getValue();
if (Regarding != null) {
var name = Regarding[0].name;
var uniqueid = Regarding[0].id;
var entType = Regarding[0].entityType;//Required ODataQuery
var context = Xrm.Page.context;
var serverUrl = context.getClientUrl();// var serverUrl = document.location.protocol + "//" + document.location.host + "/" + Xrm.Page.context.getOrgUniqueName();
var odataSelect = serverUrl + "/xrmservices/2011/OrganizationData.svc/IncidentSet?$select=new_QueueId,CustomerId,Title,TicketNumber&$filter=IncidentId eq guid'" + uniqueid + "'";
// alert(odataSelect);$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: odataSelect,
beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
success: function (data, textStatus, XmlHttpRequest) {// Multiple Entities retrieval
ProcessReturnedEntities(data.d.results);},
error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
// error: function (XmlHttpRequest, textStatus, errorThrown) { errorHandler(XMLHttpRequest, textStatus, errorThrown); }
});}
}
}function ProcessReturnedEntities(ManyEntities) {
//Prepopulate To
var to = new Array();
var cc = new Array();
var _TO = new Array();
var _CC = new Array();
var username = Xrm.Page.getAttribute("from").getValue();//alert(username[0].name);
to = Xrm.Page.getAttribute("to").getValue();
cc = Xrm.Page.getAttribute("cc").getValue();
//set only contacts
if (to != null)
for (var i = 0; i <= to.length - 1; i++) {
if (to[i].entityType == "contact")
_TO.push(to[i]);
}
Xrm.Page.getAttribute("to").setValue(_TO);if (cc != null)
for (i = 0; i <= cc.length - 1; i++) {
if (cc[i].entityType == "contact")
_CC.push(cc[i]);
}
if (cc != null)
Xrm.Page.getAttribute("cc").setValue(_CC);
//Prepopulate From
Xrm.Page.getAttribute("from").setValue(null);
var Queue = new Array();
Queue[0] = new Object();
Queue[0].id = ManyEntities[0].new_QueueId.Id;
Queue[0].name = ManyEntities[0].new_QueueId.Name;
Queue[0].entityType = ManyEntities[0].new_QueueId.LogicalName;
if (Queue[0].id != null) {
Xrm.Page.getAttribute("from").setValue(Queue);
Xrm.Page.getAttribute("bcc").setValue(Queue);
}
Xrm.Page.ui.controls.get('bcc').setDisabled(true);
//Prepopulate Subject for New Email
//var Subject = ManyEntities[0].TicketNumber + ' ' + ManyEntities[0].Title;
var sub = Xrm.Page.getAttribute("subject").getValue();
if (sub.indexOf(ManyEntities[0].TicketNumber) == -1)
// Xrm.Page.getAttribute("subject").setValue(Subject);
{
sub = sub.replace(/RE: /g, "");
sub = sub.replace(/FW: /g, "");
if (to != null)
sub = 'RE: ' + ManyEntities[0].TicketNumber + ' ' + sub;
else
sub = 'FW: ' + ManyEntities[0].TicketNumber + ' ' + sub;
Xrm.Page.getAttribute("subject").setValue(sub);
}if (Queue[0].name == null)
Queue[0].name = " ";
Xrm.Page.getAttribute("description").setValue("<br>" + "Thanks," + "<br>" + username[0].name + "<br>" + Queue[0].name + "<br>" + Xrm.Page.getAttribute("description").getValue());
Xrm.Page.ui.controls.get('regardingobjectid').setDisabled(true);}
Madhu M.
- Proposed as answer by Madhu_M Friday, May 8, 2015 9:45 PM
Friday, May 8, 2015 9:10 PM -
Hi Madhu,
Thanks for your reply.
I will check this code and will update you.
Yadav
Saturday, May 9, 2015 7:18 PM -
Mark this as Answer if this helps you.
Madhu M.
- Marked as answer by Yadav MSCRM Technical Consultant Tuesday, May 26, 2015 10:41 AM
Monday, May 11, 2015 12:52 AM