Quantcast
Channel: BugsOli's xRM blog » Customization
Viewing all articles
Browse latest Browse all 20

Calculate the remaining characters on the description field

$
0
0

Warning: this type of customization is not supported by Microsoft therefore use it at your own risks!

My client asked me if it was possible to get a “counter” on how many characters you could enter when updating the description field on an activity such as a task, a phone call, and so on.

I said “Of course it’s possible but it is not supported by Microsoft and it involves some JavaScript too”.

OK, it might not be deployed over here because of these 2 statements but still, I’m showing you how to do deal with this kind of request:

  1. Pick the entity you want to modify (in this case a phone call) and create a new attribute called “Remaining char.” (or “Car. restants” in French)
    • Type: int
    • Searchable: No
  2. Modify your form to add the newly created attributeimage
    • For more convenience, put the new attribute in ‘read-only’ mode
  3. Open the form’s properties and in the ‘onLoad’ event, place the following JavaScript code (do not forget to enable the event Wink)
    var CRM_FORM_TYPE_CREATE = 1;
    var CRM_FORM_TYPE_UPDATE = 2;
    var oDescription = crmForm.all.description;
    var oChar = crmForm.all.new_textsize;
    
    function CalculateRemainingChar()
    {
        oChar.DataValue = oDescription.MaxLength;
    
        if (oDescription.DataValue == null)
        {
            oChar.DataValue = oDescription.MaxLength;
        }
        else
        {
            oChar.DataValue = oDescription.MaxLength - oDescription.DataValue.length;
        }
    }
    
    switch (crmForm.FormType)
    {
        case CRM_FORM_TYPE_CREATE:
            oChar.DataValue = oDescription.MaxLength;
            break;
        case CRM_FORM_TYPE_UPDATE:            
            CalculateRemainingChar();
            break;
    }
    
    crmForm.all.description.attachEvent('onkeyup', CalculateRemainingChar);

  4. Save and publish your customization, then test it!

image

As always, this code is provided as-is and is not intended to be used in a production environment unless it is thoroughly tested and validated!


Viewing all articles
Browse latest Browse all 20

Trending Articles