Microsoft Dynamics CRM

{Customization and Scripting Tip} Workaround for showing some number fields without comma in Dynamics CRM

Dynamics CRM provides a wide range of fields, one of them is whole number fields.

Sometimes there is a requirement to show this whole number fields in Dynamics CRM without the “,” in the value.

This can be easily achieved if we want to remove “,” from all whole number fields by

navigating to Personal settings and remove it for all whole number fields.

However, it is not often the case when I would want to remove comma from all my whole number fields.

So, the workaround?

I went through a few options and choice is totally dependent on the business scenario at hand.

I am taking example of a Year field below:

If you have a pre-set field for year you can go for a lookup field or option set if the number of years

in the field is lesser.

In my case I have done a small text field of length 4 and added some scripting to the same

End result is something like this:

If I enter a non-numeric field in the Text year field and hit save:

clip_image001

When numeric value is entered, lets the user save:

clip_image002

Volla, without a comma, which was indeed the base of the problem.

And the script behind (You can definitely add a year range validation also, I skipped it in

This example):

function onsave(context)

{

 var stringValue = Xrm.Page.getAttribute(“dynamics_year”).getValue();

 var numberValue = parseInt(stringValue);

    if(isNaN(numberValue)) {

    Xrm.Page.ui.setFormNotification(“Year is not entered in correct format.”, “ERROR”,“1”);

    // Do not let user save

    context.getEventArgs().preventDefault();

    } 

    else

    {

     Xrm.Page.ui.clearFormNotification(‘1’);

    }

}

 

One last thing, to note: During registering the script on save event on the form do not forget

the highlighted checkbox (to pass the context to the script as first parameter):

clip_image001[4]

Hope it helps and Happy CRMing!

Advertisements

3 thoughts on “{Customization and Scripting Tip} Workaround for showing some number fields without comma in Dynamics CRM”

  1. The only issue with this approach is that it reduces the searchability of the Year field. For e.g. you can’t do an advanced find where Year < 2015. IMHO, having a comma is a small price to pay for searchability.

    1. Hi Natraj,

      All customers do not want to see , in fields like years. This is a big issue for them on reporting as well. For searching based on the field types a similar approach can be applied similar to what I have needed in past where customers have requested me to have wild card search on whole number fields:

      https://dynamicsofdynamicscrm.wordpress.com/2015/01/12/zero-code-development-quick-find-wild-card-search-on-whole-number-field-in-dynamics-crm-2015/

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