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 :
Customer experience | Sales, Customer Insights,...
Answered

Extraction of email domain through email address field.

(1) ShareShare
ReportReport
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! 
I have the same question (0)
  • Suggested answer
    PerezAguiar Profile Picture
    Microsoft Employee on at
    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,
  • Dengliang Li Profile Picture
    Microsoft Employee on at
    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
  • Talal Tariq Profile Picture
    24 on at
    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
  • Verified answer
    Dengliang Li Profile Picture
    Microsoft Employee on at
    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
    24 on at
    Hi Dengliang,
     
    Just updated the code you shared and it is working perfectly.
     
    Thanks!

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans