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

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

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 60 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 52 Super User 2025 Season 2

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 36 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans