Wednesday, June 11, 2014

Mask Phone number, Date fields in CRM

NOTE: THIS IS UNSUPPORTED CRM 2013 CUSTOMIZATION.

For Complete code check https://maskedinputcrm2013.codeplex.com

To provide masking for input fields in CRM form we can use jQuery masked input plugin.
 Using this plugin we can easily add masking for not only phone number, fax, date fields but also we can add masking for like SSN number, driving license number etc.
Also when adding this masking, this plugin is already taking care of inputs validation like phone number should contain only numbers.
 We can add our own formats also using this plugin. For more details about this plugin, Check  http://digitalbush.com/projects/masked-input-plugin/
For CRM implementation
·         Download minified masked input plugin file from https://raw.github.com/digitalBush/jquery.maskedinput/1.3.1/dist/jquery.maskedinput.min.js
·         Add this JS file to CRM web resources.
·         Create new JavaScript web resource and add following code in that file
var CustomMaskScript = {
    MaskInputField: function (fieldName, format) {       
        var control = Xrm.Page.getControl(fieldName);
        if (control != null && control.getControlType() == 'standard') {
            control.setFocus();
            if (Xrm.Page.getAttribute(fieldName).getAttributeType() == 'datetime') {
                var input = $("#" + fieldName + "_i").find("input");
                if (input != null)
                    input.mask(format);
            } else
                $("#" + fieldName + "_i").mask(format);
        }
    },
};


·         Now add both file in entity form library where you want to use masking

  •   Call MaskInputField function on load of Form with attribute name and Format as parameters.

'new_birthdate','99/99/9999'
·         Save and publish customization.
·         And maked input is ready to use

Above example is for manual masking for fields which we can to add masking.

If by default we want to add masking for all phones and date attributes on Form then use following script

var DefaultMask = {
    MASK_date: '99/99/9999',
    MASK_Phone: '(999) 999-9999',

    MaskDatePhoneInput: function () {
        var PageAttributes = Xrm.Page.data.entity.attributes.get();
        var fieldName = '';
        var Format = '';
        for (var i in PageAttributes) {
            var control = PageAttributes[i].controls.get(0);
            fieldName = PageAttributes[i].getName();
            Format = PageAttributes[i].getFormat();
            if (Format == 'phone' || Format == 'date') {
                control.setFocus();
                if (PageAttributes[i].getAttributeType() == 'datetime') {
                    var input = $("#" + fieldName + "_i").find("input");
                    if (input != null)
                        input.mask(ContactDefaultMask.MASK_date);
                } else
                    $("#" + fieldName + "_i").mask(ContactDefaultMask.MASK_Phone);
            }
        }
    },
}
Add this in JS web resources and call function on load.  This will add masking for all phone number and date fields on Form.

Here are some examples of masking 
·         Date
Without Mask:

With Mask

Mask Format:  99/99/9999

·         Phone number
Without Mask:


With Mask


Mask Format:  (999) 999-9999

·         Phone number with Extension
Without Mask:


With Mask


Mask Format:  (999) 999-9999? X99999

·         Social Security Number
Without Mask:


With Mask


Mask Format:  999-99-9999

·         Custom (e.g. Wisconsin Driving license)
Without Mask:


With Mask


Mask Format:  a-9999999999


For Complete code check https://maskedinputcrm2013.codeplex.com



8 comments:

  1. I really liked your blog. It has a sense of humor and quite interesting. Good job guys. Looking forward for more updates.

    Books and Manuals
    www.gofastek.com

    ReplyDelete
  2. Hi i need to add multiple mask on firld
    then ahat will be syntax

    either - 'fieldname','mask','fieldname','mask'

    like this -'new_birthdate','99/99/9999','new_ssnumber','999-99-9999'

    but its not working please suggest

    ReplyDelete
  3. Have you used this on Dynamics CRM 2016? I can get it to work but then I navigate to another record and I get an error.

    TypeError: Object doesn't support property or method 'mask'

    appears that the masked input plugin is getting lost but I can't figure out why.

    ReplyDelete
  4. This is not working CRM 2016.Has anyone did the same in CRM 2016?

    ReplyDelete

  5. Amazing Blog! Thanks for sharing, If you want to buy online personalized face masks from photo India, then visit us.

    ReplyDelete

  6. Among these few are budget friendly. Like, Printland.in You can not only print bulk of Amazing Blog! Thanks for sharing, If you want to buy online mask printing, then visit us. for men, women and kids, but you will get additional discounts as well which are indeed lucrative. So, dry try it’s products. These are really good ones.

    ReplyDelete
  7. Thanks for sharing creative designs for face masks. You can check this link for more information.
    Custom Face Masks

    ReplyDelete
  8. Data is one of the most important things that customers or companies do not want to share with an unknown person. GetItSMS has the best way to communicate with customers without displaying a number. Phone Number Masking India service will help you with voice solutions to communicate between customers and agencies.

    Though, the service of phone number masking is not limited to a few benefits to the agencies and customers. Using phone number masking will help the company’s record avoid as well. Which they can use to improve their services or products as well. Phone number masking is absolutely a protected service that will help businesses communicate in an effective and efficient way. Number masking is absolutely a top service that businesses can use to protect their data and communicate without any headache.

    With a mask, phone number customers can start communication with the agency. Companies that are absolutely sensitive about data protection for both the personal and business. Call mask technology will help them out and provide them with a perfect voice call solution.

    ReplyDelete