web
You’re offline. This is a read only version of the page.
close
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);

I have the same question (0)
  • 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 45 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 27 Most Valuable Professional

#3
Soundari Profile Picture

Soundari 15

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans