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 :
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

I have the same question (0)
  • Lakshmi Priya Profile Picture
    20 on at

    Hi ChrisJC

    I am facing the same problem.

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

  • Suggested answer
    ChrisJC Profile Picture
    1,540 on at

    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

  • Suggested answer
    Azamba Profile Picture
    5 on at

    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
        }
    }

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans