Removing commas from integer fields in CRM 2011

已答复 Removing commas from integer fields in CRM 2011

  • mardi 22 mai 2012 17:12
     
      A du code

    Hi,

    How can we remove commas from the integer fields using JavaScript in CRM 2011?

    We can easily do that in CRM 4 using this code snippet:

    if(crmForm.all.fieldname != null && crmForm.all.fieldname.DataValue != null)

    {

    crmForm.all.fieldname.value = crmForm.all.fieldname.DataValue;

    However, It seems that MS has converged field.value and field.DataValue into simply getAttribute("fieldname").getValue();

    Is there any way to remove the auto placed commas in the integer field using JavaScript?

    Thanks!!!


Toutes les réponses

  • mardi 22 mai 2012 23:48
     
     Traitée

    Why do you wish to do this?

    The number stored in the database will be numeric (no grouping characters) and all programmatic access to the value, be it via Form Javascript or CRM Web Services, will return that numeric value.

    You should not be interacting directly with the value displayed; it is unsupported in CRM 2011 and your CRM 4.0 solution was equally unsupported.

    If all you wish to do is control the way that numbers display, you can do so via System and/or User Settings:


    --pogo (pat) @ pogo69.wordpress.com

  • mercredi 23 mai 2012 12:29
     
     

    Hi,

    What I wanted to do is to remove the commas as shown below in the Total Cases/Minutes:

    

    If I use the Customize Regional Settings, it'll change the format for each and every Integer field in CRM 2011 form. I'd however only want this particular field's value to be not grouped.

    Can we try to suppress the lostFocus method of this field so that it doesn't group the value?

    Or is there any other workaround using JavaScript?

    Thanks!!!

  • jeudi 24 mai 2012 00:32
     
     Traitée A du code

    You can get at the underlying HTML element value by hacking at the DOM (which is essentially what your CRM 4.0 solution was doing) as per the following:

    document.getElementById("fieldname").value = Xrm.Page.data.entity.attributes.get("fieldname").getValue();
    I would highly advise against it, unless you had a very good reason for it.  Such unsupported customisations are highly likely to break in future versions of CRM, particularly with the forth-coming cross-browser capabilities.


    --pogo (pat) @ pogo69.wordpress.com

  • lundi 4 juin 2012 18:20
     
     

    I tried almost all possible solutions but couldn't get it.

    However, we later 'fixed' it by changing the type of the field, in this case from a whole number to a single line of text field. That change made sure that no commas are auto placed. However, now we needed to implement extra checks; preventing non-numeric values and that was easy.

    Glad, it's done :) Thanks pogo69 :D