Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

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

(0) ShareShare
ReportReport
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,056 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

News and Announcements

Announcing Category Subscriptions!

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans