Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Answered

How to remove an email address from a list of email addresses from "To" field of an email record?

(0) ShareShare
ReportReport
Posted on by 255

Hi folks,

there is a requirement to remove a specific email address from "To" field which has a list of email addresses using Javascript.

i have done this to remove a specific mail but this is not working. Please help me in this regards.

var formContext = executionContext.getFormContext();

var toParty = Xrm.Page.getAttribute("to").getValue();

var partyListArray = new Array();
for (var indx = 0; indx < toParty.length; indx++) {
var email = getParticipantEmail(
toParty[indx].entityType,
toParty[indx].id
);
if (email != "test@test.com") {
partyListArray[indx] = new Object();
partyListArray[indx].id = toParty[indx].id;
partyListArray[indx].name = toParty[indx].name;
partyListArray[indx].entityType = toParty[indx].entityType;
}
}

Xrm.Page.getAttribute("to").setValue(null);
Xrm.Page.getAttribute("to").setValue(partyListArray);

  • Suggested answer
    Anant Profile Picture
    255 on at
    RE: How to remove an email address from a list of email addresses from "To" field of an email record?

    Thanks Steve. Got your point..

  • Verified answer
    Community Member Profile Picture
    on at
    RE: How to remove an email address from a list of email addresses from "To" field of an email record?

    Hi Anant wrote,

    I tested this code and it can achieve this:

    async function onload(executionContext){
    	var formContext = executionContext.getFormContext();
    
    	var toParty = Xrm.Page.getAttribute("to").getValue();
    
    	var partyListArray = new Array();
    	for(var indx = 0; indx < toParty.length; indx  ){
    		var email = await getParticipantEmail(
    			toParty[indx].entityType,
    			toParty[indx].id
    		);
                    console.log(email);
    		if(email != "test@test.com"){
    		partyListArray[indx] = new Object();
    		partyListArray[indx].id = toParty[indx].id;
    		partyListArray[indx].name = toParty[indx].name;
    		partyListArray[indx].entityType = toParty[indx].entityType;
    		}
    	}
    
    	Xrm.Page.getAttribute("to").setValue(null);
    	Xrm.Page.getAttribute("to").setValue(partyListArray);
    }
    
    async function getParticipantEmail(entityType,id){
    	var result = await Xrm.WebApi.retrieveRecord(entityType, id, "?$select=emailaddress1");
    	return result.emailaddress1;
    }

    Result:

    0250.kb.gif

    In my case, I just add Contact and Account into "to" field. If you add other entities such as User, you should change the email's logical name in my code.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 51 Most Valuable Professional

#2
Ramesh Kumar Profile Picture

Ramesh Kumar 42

#3
David Shaw_UK Profile Picture

David Shaw_UK 27

Featured topics

Product updates

Dynamics 365 release plans