Upgrading to CRM 2013 and I found that Field masking I was using in CRM 2011 doesn’t work any more.

Here is a fix I got. (Thanks to guy who posted it on this link)

In crm 2011 input field ID is the name of attribute, while in crm 2013 input field ID is the name of attribute plus “_i” (may be “i” denote an input).

So if we have attribute name “name” then input field ID for this attribute in 2011 is “name” and in 2013 it is “name_i”.

Following is the Source view of input field of an attribute on the form in crm 2011 and crm 2013.

Input field in crm 2011

Input field in crm 2013

//Include jquery and jqueryMask plugin file on form you apply masking.
function Mask(field, format)
{
$(“#”+field).mask(format);
}

// call this function on form load event
function maskFields()
{
Mask(“address1_postalcode”, “99999-9999”);
Mask(“telephone1”, “(999) 999-9999”);
Mask(“telephone2”, “(999) 999-9999”);
Mask(“fax”, “(999) 999-9999”);

}
For crm 2013 you should attach “_i” with field name like.

function Mask(field, format)
{
$(“#”+field+”_i”).mask(format);
}
But also still not working because in crm 2013 input fields are created on execution time. you should apply masking on click event of input, or just got focus of attribute before apply masking e.g.

//Include jquery and jqueryMask plugin file on form you apply masking.
function Mask(field, format) {
//first check whether attribute exist or not
var oCtrl = Xrm.Page.getControl(field);
if (oCtrl != null) {

oCtrl.setFocus(true);
$(“#” + field + “_i”).mask(format);
}
}

// call this function on form load event
function maskFields()
{
Mask(“address1_postalcode”, “99999-9999”);
Mask(“telephone1”, “(999) 999-9999”);
Mask(“telephone2”, “(999) 999-9999”);
Mask(“fax”, “(999) 999-9999”);

}

 

Hope it helps someone!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s