Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Suggested answer

How to mask the phone number on a quick view form?

Posted on by 2,645

I need to mask the phone number on an Account Contact card (Quick Create Form), can this be done?  If so,  how?  I have done this on the actual Contact form, just can't seem to find a way to do it on a quick create form.

Please advise, thank you.

  • Suggested answer
    Nya Profile Picture
    Nya 29,054 on at
    RE: How to mask the phone number on a quick view form?

    Hi, USA80

    Do you mean to auto format the mask of the highlighted phone number in the image below?

    0.png

    1. If so, you can create a JavaScript web resource.

    Here is the code.

     

    function FormatPhoneNo(executionContext) {
        try {
            var formContext = executionContext.getFormContext();
            var nvsField = formContext.getAttribute("telephone1").getValue();
            var nvsTmp = nvsField;
            if (typeof(nvsField) != "undefined" && nvsField != null) {
                nvsTmp = nvsField.replace(/[^0-9]/g, "");
                switch (nvsTmp.length) {
                    case 10:
                        nvsTmp = "("   nvsTmp.substr(0, 3)   ") "  
                            nvsTmp.substr(3, 3)   "-"   nvsTmp.substr(6, 4);
                        break;
                    default:
                        alert("Phone must contain 10 numeric digits.");
                        break;
                }
            }
            context.getEventSource().setValue(nvsTmp);
        } catch (err) {
            alert(err.message);
        }
    }

    1. Open the JavaScript to the Quick Create Form of Contact entity and click the Form Properties.

     8880.png

    1. Add the JavaScript to the Quick Create Form and set the Event Handle as the image below.

     88730.png

    1. Add the function.

     35232.png

    1. Save and publish the form.

    Then the Phone Number will be masked as the format: (xxx) xxx-xxxx.

    pastedimage1613109218527v2.png

    And if a number which has been input does not contain 10 digits, there will be prompt popping up.

    pastedimage1613109197122v1.png

    You need to modify the code yourself for the specific format.

     

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Nya

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 228,645 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans