locked
CRM 2011 - override built in validation RRS feed

  • Question

  • Hi There

    I am trying to write a Jscript code for CRM 2011.
    I want to create code that allows a user to type "3m" into an attribute and have this automatically fill in "3000000" (ie: 3m = 3 million).
    I want to do this for at least 50 fields throughout the system.

    I tried adding an onChange event but CRM's built in validation picked up that the "m" was not a numeric character before my code even fired.

    I need to add an event which triggers before the built in validation. Is this possible ?

    Regards

    Jonathan
    Tuesday, August 2, 2011 10:20 AM

Answers

  • Hello Jonathan,

     

    I don't have at the moment access to any CRM 2011 so I tried to do this trick with CRM 4.0 and it worked. I think it would not be the issue to force work it for 2011. Here is the code which should be inserted to OnLoad of CRM form:

     

    DecodeValue = function(fieldname)
    {
    var control = document.getElementById(fieldname)
    
    if (control != null)
    control.attachEvent("onkeyup", function()
    {
    var val = control.value;
    if (val == null)
    return;
    control.value = val.replace("M", "000000")
    })
    }
    
    DecodeValue("dc_purchaseprice");//Paste here the name of field
    



    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Tuesday, August 2, 2011 11:46 PM
    Moderator

All replies

  • Hi Jonathan,

     

    Not really - I mean you cannot do anything before the system validation for int fields in a supported way. I suggest adding a text field and hiding the int field. Then add some JScript code on OnChange event to populate the int field with the right value based on what the user enters, e.g. 3m -> 3 000 000. That's the only supported way that comes into my mind and still guarantees you will have proper integer values in the int fields and not report on tedxt fields to find numbers.

     

    I hope that helps,

    Kuba


    -- Kuba Skałbania, Netwise
    Tuesday, August 2, 2011 8:25 PM
  • Hello Jonathan,

     

    I don't have at the moment access to any CRM 2011 so I tried to do this trick with CRM 4.0 and it worked. I think it would not be the issue to force work it for 2011. Here is the code which should be inserted to OnLoad of CRM form:

     

    DecodeValue = function(fieldname)
    {
    var control = document.getElementById(fieldname)
    
    if (control != null)
    control.attachEvent("onkeyup", function()
    {
    var val = control.value;
    if (val == null)
    return;
    control.value = val.replace("M", "000000")
    })
    }
    
    DecodeValue("dc_purchaseprice");//Paste here the name of field
    



    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Tuesday, August 2, 2011 11:46 PM
    Moderator