9 Ocak 2011 Pazar

How to format a number field(integer) without showing commas?

There is an interesting topic on the CRM Forum about how to format an integer field without commas. For example, if you type: 123456 in an integer field, you may see 123,456 once it loses focus. CRM automatically add a ',' between 3 numbers. There's a global setting to get rid of it, however, it will get rid of all integer field format. How about if you just want to remove the format for just one field?

As you may know, MSCRM uses htc files to format the different type of input fields as same as email address etc, see my another post.

If you want to get the value of an attribute, in CRM we use: DataValue, e.g: crmForm.all.new_number.DataValue;
Notice that the DataValue is the real data saved in the database.

However, if you want to get the formatted value, you may use this:
crmForm.all.new_number.value;

So the trick is give the DataValue overwrites the value property.

Put the following code into the entity's onLoad() event, and the same code puts into the field's onChange() event.

if(crmForm.all.new_number != null && crmForm.all.new_number.DataValue != null)
{
crmForm.all.new_number.value = crmForm.all.new_number.DataValue;
}

Enjoy it!


crm consulting |sales force |crm business intelligence |database software |crm magic quadrant |

Hiç yorum yok:

Yorum Gönder