Skip to main content

Notifications

Announcements

No record found.

Service | Customer Service, Contact Center, Fie...
Answered

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

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

  • Kae Profile Picture
    Kae 150 on at
    RE: Automatically assign a Mailbox Queue to "From " field in an email instead of user's name

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

  • Jolas365 Profile Picture
    Jolas365 235 on at
    RE: Automatically assign a Mailbox Queue to "From " field in an email instead of user's name

    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

  • Jolas365 Profile Picture
    Jolas365 235 on at
    RE: Automatically assign a Mailbox Queue to "From " field in an email instead of user's name

    Hi ,

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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Automatically assign a Mailbox Queue to "From " field in an email instead of user's name

    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
    Jolas365 235 on at
    RE: Automatically assign a Mailbox Queue to "From " field in an email instead of user's name

    Hi Steve,

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

    Thanks

    Jolas365

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Automatically assign a Mailbox Queue to "From " field in an email instead of user's name

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans