web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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);

  • Verified answer
    Community Member Profile Picture
    on at

    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.

  • Suggested answer
    Anant Profile Picture
    255 on at

    Thanks Steve. Got your point..

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
11manish Profile Picture

11manish 48 Super User 2026 Season 2

#2
Travis South Profile Picture

Travis South 45

#3
Ayesha Wajahat Profile Picture

Ayesha Wajahat 18

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans