CRM 2011 SMS custom activity Characters Remaining field

Paul Nieuwelaar in his blog has implemented some javascript for the characters remaining field.

This saves me a lot of time from reinventing the wheel. All I then did was to set the default value to the field (160 characters for SMS).

Also make sure that you put the 160 limit on the multiline textbox, but leave the minimum value for the charactersremaining field to be -20000000 to avoid the annoying message box.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function Form_onload() {
    //set max characters
    keyPress();
    document.getElementById("description").onkeyup = keyPress;
    document.getElementById("description").onkeydown = keyPress;
}
 
function keyPress() {
    var maxLength = 160;
    var charRemaining = Xrm.Page.getAttribute("new_charactersremaining");
    var message = document.getElementById("description");
    var messageVal = message.value;
    if (messageVal != null) {
        var msgLength = messageVal.length;
        var remaining = maxLength - msgLength;
        charRemaining.setValue(remaining);
    }
    else {
        charRemaining.setValue(maxLength);
    }
}


Hope this helps,
Andreas

Comments

Popular posts from this blog

SharePoint 2013 anonymous access add attachments to list item

CRM Plugin - Parent and Child Pipeline