Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / Extraction of email do...
Sales forum
Answered

Extraction of email domain through email address field.

Posted on by 24
Hi there,
 
I'm having business requirement that we need to extract Email Domain (e.g. @gmail.com, @yahoo.com etc.) from Email Address field in CRM. I have already created Email Domain field within the system and now it is required that email domain should be extracted and auto-populated within the Email Domain field from Email Address.
 
Is there any OOB functionality or any other solution that might help me in achieving this requirement?
 
Please suggest if there's any solution to it, thanks! 
  • Talal Tariq Profile Picture
    Talal Tariq 24 on at
    Extraction of email domain through email address field.
    Hi Dengliang,
     
    Just updated the code you shared and it is working perfectly.
     
    Thanks!
  • Verified answer
    Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    Extraction of email domain through email address field.
    Hi
    This issue occurs when the email address is empty. According to your question, we have improved the script. It is as follows. 
     
    var Example = window.Example || {};
    (function () {
        // Code to run in the form OnLoad event
        this.formOnLoad = function (executionContext) {
            var formContext = executionContext.getFormContext();
            var str = formContext.getAttribute("emailaddress1").getValue();
            if (str == null) {
                formContext.getAttribute("credf_emaildomain").setValue(emailDomain);
            }
            else {
                var indexs = str.indexOf("@");
                var emailDomain = str.substring(indexs, str.length);
                formContext.getAttribute("credf_emaildomain").setValue(emailDomain);
            }
        }
    }).call(Example);
     
    We added conditional judgment: when the email address is empty, the email Domain field is also empty; when the email address is not empty, the email Domain field is automatically populated with the email domain.
     
    We recommend replacing the previous script with this new script or creating a new JS file with this new script.

     
    After that, replacing the JS file in the previously used Web reource with the new JS file, save and publish it. In this way it will simplify the steps and reduce the risk of errors due to cumbersome steps.

     


     
    If my answer was helpful, please click "Like", and if it solved your problem, please mark it as "Verified" to help other community members find more.
    If you have further questions, please feel free to contact me .

    Best Regards,
    Dengliang Li
  • Talal Tariq Profile Picture
    Talal Tariq 24 on at
    Extraction of email domain through email address field.
    Hi Dengliang,
     
    I tried implementing the solution workaround you shared and it seems to be working in a great manner.
     
    Though, I'm just concerned that whenever I try to create a New Lead from scratch, I come across the following error:
     
     
    Just wanted to confirm that if I'm not doing any step wrong. Your feedback/suggestion would be valuable for me.
     
    Thanks & Regards,
    Talal Tariq
  • Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    Extraction of email domain through email address field.
    Hi,
     
    Based on the information you provided, we conducted some related tests. We found that with client-side scripting we could achieve the desired functionality.
     
    The testing procedure is as follows:
    Step 1. Designing the Client Script.
     
    var Example = window.Example || {};
    (function () {
    // Code to run in the form OnLoad event
        this.formOnLoad = function (executionContext) {
            var formContext = executionContext.getFormContext();
            var str = formContext.getAttribute("emailaddress1").getValue();
            var indexs = str.indexOf("@");
            var emailDomain = str.substring(indexs,str.length);
            return formContext.getAttribute("credf_emaildomain").setValue(emailDomain);
        }
    }).call(Example);
     
    In the script: return formContext.getAttribute("credf_emaildomain").setValue(emailDomain);
    The "credf_emaildomain" in this line of code refers to the logical name of the customized email domain field.

     
    Step 2. Using the client-side script.
    1. Upload client side script to Sales trial form. The Contact form is used here as an example.

     
    1. Locate the whole form and add OnLoad event in Event tab. The event handler will use the client script that was just uploaded.

     
    Step 3. Test the script.
    1. Open Sales trial and select a Contact record.

     
    1. The Email Domain field is automatically populated with the email domain of the Email address.

     
    I hope my answer is helpful to you! If you have any other questions, please feel free to contact me.
     
    Best Regards,
    Dengliang Li
  • Suggested answer
    PerezAguiar Profile Picture
    PerezAguiar on at
    Extraction of email domain through email address field.
    Hey.
     
    Unfortunatelly, there's no Out of the Box component for this.  However, there's a simple functionality you can use:  YOu can use PowerAutomate.  With a Dataverse connector, you can use a simple trigger (run once if you need to proceed with data already uploaded, or "on modify of field" to trigger everytime the "email" field is updated.  

    With this connector you can retrieve the value of this particular field (Email), use a Compose action to extract a substring, and then insert the value of the compose on the field you need.
     
    Regards,

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,353 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,251 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans