Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Remove email recipient using javascript

(0) ShareShare
ReportReport
Posted on by 1,540

I'm using Dynamics 365 online v9.1.

Where emails are linked to a case I want to change the From to be the support queue and make sure they're not a recipient.

The From change is working perfectly.

The To (and CC) checks are working when the email form loads. When the email record is saved, the queue is added back as a To recipient. I have my function registered on form load only, not save. However I can't see any reference to the function being called on save using Fiddler or Console.

writeToConsole("Cycle To");
if (tos.length > 0)//tos !== null && //works with or without null check
    for (i = 0; i < tos.length; i++) {
        var _to = tos[i];
        writeToConsole(_to);
        if (_to["id"].replace("{", "").replace("}", "") === queueId) {
            writeToConsole("Remove queue from To");
            tos.splice(i, 1);
            upTo = true;
        }
        else {
            writeToConsole("no match");
            writeToConsole(_to["id"]);
            writeToConsole(queue[0].id);
        }
    }
if (upTo) {
    writeToConsole("Update Tos");
    Xrm.Page.getAttribute("to").setValue(null);// doesn't seem to matter
    Xrm.Page.getAttribute("to").setValue(tos);
}


*This post is locked for comments

  • Suggested answer
    Azamba Profile Picture
    Azamba 5 on at
    RE: Remove email recipient using javascript

    function setRecipients(executionContext) {
        debugger;
        let formContext = executionContext.getFormContext();
    
        varlookupTo = formContext.getAttribute("to").getValue();
    
        let tos_update = new Array();
        if (varlookupTo.length > 0)
        {
            for (i = 0; i < varlookupTo.length; i  ) {
                var _to = varlookupTo[i];
                if(varlookupTo[i].name != "Customer Support"){ //
                    var _c = new Object();
                    _c.id = _to["id"];
                    _c.name = _to["name"];
                    _c.entityType = _to["entityType"];
                
                    tos_update[tos_update.length] = _c;
                }
            }
            formContext.getAttribute("to").setValue(tos_update); //this should be updated to the new libraries
        }
    }

  • Suggested answer
    ChrisJC Profile Picture
    ChrisJC 1,540 on at
    RE: Remove email recipient using javascript

    Yes, to resolve this I ended up create a new update object and only adding the 'to' recipients to it that I needed.

    I then set the value of the 'to' attribute to this update object.

    if (tos.length > 0)
    {
        for (i = 0; i < tos.length; i  ) {
            if(){
                var _c = new Object();
                _c.id = _to["id"];
                _c.name = _to["name"];
                _c.entityType = _to["entityType"];
    
                tos_update[tos_update.length] = _c;
            }
        }
    }
    
    Xrm.Page.getAttribute("to").setValue(tos_update); //this should be updated to the new libraries

  • Lakshmi Priya Profile Picture
    Lakshmi Priya 20 on at
    RE: Remove email recipient using javascript

    Hi ChrisJC

    I am facing the same problem.

    Is your problem solved? If so, can you please specify how you solved it.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans