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

Automatically assign a Mailbox Queue to "From " field in an email instead of user's name

(0) ShareShare
ReportReport
Posted on by 235

Hello CS Experts,

I have asked a similar question before but was not able to get a working solution so I am posting this again.

My scenario is I have two service agents : A and B.

Service agent A is a member of Alpha queue and B is a member of Bravo queue.

When Service agent A sends out an email from CRM, the "From" field of the email should contain "Alpha" instead of Service agent A name.

When Service agent B sends out an email from CRM, the "From" field of the email should contain "Bravo", instead of Service agent B name.

If you have had this scenario before, how did you implement it? 

Thank you very much!

Regards,

Jolas365

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Jolas365,

    Have you tried to use JS to achieve this? Add an onload and onchange event to check the sender. If the sender is Alpha then get this user's id to query the queue he is in. Finally, clear the “From” field and set its value as  Alpha queue.

  • Jolas365 Profile Picture
    235 on at

    Hi Steve,

    Thanks for your prompt reply. I might be asking too much, but, do you have the actual JS codes, please.

    Thanks

    Jolas365

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Jolas365,

    Please try this:

    function onload(executionContext){
    debugger;
    var formContext = executionContext.getFormContext();
    var clientUrl = Xrm.Utility.getGlobalContext().getClientUrl();

    var sender = formContext.getAttribute("from").getValue()[0];
    if(sender.name == "System Administrator"){
    var senderid = sender.id.replace('{','').replace('}','');
    console.log(senderid);
    var uri = clientUrl + "/api/data/v9.2/systemusers(" + senderid + ")/Microsoft.Dynamics.CRM.RetrieveUserQueues(IncludePublic=false)";
    var request = new XMLHttpRequest();
    request.open("get", uri , true);
    request.setRequestHeader("OData-MaxVersion", "4.0");
    request.setRequestHeader("OData-Version", "4.0");
    request.setRequestHeader("Accept", "application/json");
    request.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    request.onreadystatechange = function () {
    if (request.readyState === 4) {
    debugger;
    var queues = JSON.parse(request.responseText).value;
    queues.forEach(function(item){
    if(item.name == "Default Queue"){
    var lookupVal = new Array();
    lookupVal[0] = new Object();
    lookupVal[0].id = item.queueid;
    lookupVal[0].name = item.name;
    lookupVal[0].entityType = "queue";
    console.log(lookupVal);
    formContext.getAttribute("from").setValue(lookupVal);
    }
    })
    }
    }
    request.send();
    }
    }

    My test:

    changeSender.gif

  • Jolas365 Profile Picture
    235 on at

    Hi ,

    You are a Superman! This is working. Thank you ever so much!

  • Jolas365 Profile Picture
    235 on at

    Hello Steve,

    I just found out from my testing that this will work only when users are assigned to the root Business Unit. When a user is under a Child BU, the code stops to work yet there is no error.

    Regards,

    Jorge

  • Kae Profile Picture
    150 on at

    Hello, can you help me where I should enter these codes?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 30 Super User 2026 Season 1

#2
NeerajPawar Profile Picture

NeerajPawar 22

#3
Eugen Podkorytov Profile Picture

Eugen Podkorytov 14

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans