Recently I have been working on a solution in Dynamics CRM 2011, which required me to store and display the characters remaining in a text field, as the user is typing into the field.  This ‘Characters Remaining’ field needed to be live updating every time someone enters a character into the text field, so using the standard methods of ‘onChange’ would not quite work, as it would only update once you click out of the field.

There were a few ‘Gotchas’ that I encountered while attempting this seemingly simple task. But before I got to any of those, I first got the JScript working on the fields onchange, so that when someone clicks out of the text box after entering data, the Characters Remaining field will be set to 100 minus the field values length. This was easily achieved using the following JScript, with the ‘keyPress’ function being called onchange on the text field.

function keyPress() {
var charRemaining = Xrm.Page.getAttribute(“mag_charactersremaining”);
var message = Xrm.Page.getAttribute(“description”);
var messageVal = message.getValue();
var maxLength = 100;
if (messageVal != null) {
var msgLength = messageVal.length;
var remaining = maxLength – msgLength;
charRemaining.setValue(remaining);
}
else {
charRemaining.setValue(maxLength);
}
}

Note: WordPress formats code weird, to download all code used in this blog post click here.

In this example, the charRemaining variable sets the ‘Characters Remaining’ field, and the message variable sets the name of the text field we’re entering data into. Also the maxLength variable sets the starting value of the Characters Remaining field (this will be what it counts down from, in this case 100).

So using this alone works well, however it doesn’t work each time we type a character, which is what we want to happen. So to do this we need to call the function above when a character is typed within our text field. I eventually found the following line of code which will fire the ‘keyPress’ function when a key is pressed inside the text field.

document.getElementById(“description”).onkeypress = keyPress;

However this was where the first ‘gotcha’ happened. Although adding the above line of code to the onload event would fire the ‘keyPress’ function when a key was pressed, it would not include certain characters such as backspace, enter, or delete. Other options were using ‘onkeydown’ instead of ‘onkeypress’, although this didn’t quite work as expected either, as it was only called when the next key was pressed, where as we wanted to fire when the current key was pressed. So instead we used ‘onkeyup’ which did the job, although using this method didn’t fire the event until the key was released, so if you held down a key it wouldn’t change the Characters Remaining until you released that key. After a bit of testing, I found that adding 2 separate lines for ‘onkeyup’ and ‘onkeydown’ worked exactly how we wanted. The full function to call in the onload looks like this:

function onLoad() {
document.getElementById(“description”).onkeyup = keyPress;
document.getElementById(“description”).onkeydown = keyPress;
}

 

While this was now firing the keyPress event correctly, the Characters Remaining wasn’t changing until you clicked out of the text field. I discovered this was because the ‘message length’ isn’t saved until you click out of the field. However I managed to find a work around for this. Instead of using ‘Xrm.Page.getAttribute’ to get the message field, I used ‘document.getElementById’. Which when used with message length got the current length of the field at the time.

This was now working exactly as I wanted, the last step was to add the keyPress function to the onload, so that when the form loads, the Characters Remaining will be set to the correct amount. I’ve added the full JScript file below:

function keyPress() {
var charRemaining = Xrm.Page.getAttribute(“mag_charactersremaining”);
var message = document.getElementById(“description”);
var messageVal = message.value;
var maxLength = 100;
if (messageVal != null) {
var msgLength = messageVal.length;
var remaining = maxLength – msgLength;
charRemaining.setValue(remaining);
}
else {
charRemaining.setValue(maxLength);
}
}

function onLoad() {
document.getElementById(“description”).onkeyup = keyPress;
document.getElementById(“description”).onkeydown = keyPress;
}

 

Download code used in this post (wordpress formats it weird).

Download UR 17 for Dynamics CRM 4.0 from here:
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=94fa9f74-f574-4c24-a42f-915f1a843f44&displaylang=en

I’ve added links below to all my posts on the knowledge base in Dynamics CRM 2011. You should find everything Article related here.

Where is the Knowledge Base in Dynamics CRM 2011?
The Lifecycle of an Article in Dynamics CRM 2011
Creating an Article in Dynamics CRM 2011
Creating and Editing an Article Template in Dynamics CRM 2011
What to Check for when Approving an Article in Dynamics CRM 2011
Commenting on an Article in Dynamics CRM 2011
How to Insert an Image into your Dynamics CRM Article
Searching for Articles in Dynamics CRM 2011
Customizing an Article Form in Dynamics CRM 2011
Inserting a Dynamics CRM 2011 Article into an Outlook Email

The first update rollup for Dynamics CRM 2011 has recently been released.

To download and install the updates yourself use the following link:
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=8cd2384e-e06a-4cf1-800d-303aec37f40b

Otherwise wait until the end of April and it will be available as a windows update.

Also check out the KB Article describing the issues resolved:
http://support.microsoft.com/default.aspx?kbid=2466084

Rollup 15 for Microsoft Dynamics CRM 4.0 has been released, download and install from Microsoft and get your system up to date.
http://www.microsoft.com/downloads/details.aspx?FamilyID=A43147C9-E87E-41B3-BF46-AC1244A0475C&displaylang=ja&displaylang=en

paulnieuwelaar.com has a new website

Posted: January 10, 2011 in Other

From now on paulnieuwelaar.com is no more, and the site will now be hosted on this site, paulnieuwelaar.wordpress.com. Same content, same author, new domain, new theme.

Old Site Theme

Here’s another obvious one that will save you lots of time accessing your FTP site. No more going through your browser, logging in, and then opening your FTP in Windows Explorer to get an easy to use folder view.

For ages I’ve been doing exactly that, which is a pain to need to go through all of that just to open your FTP site in windows explorer. I’ve discovered a much better way to access your FTP, so that all you need to do to open your FTP in windows explorer is open a shortcut on your desktop, no browsers or logging in required.

Recently someone showed me a way to log into an FTP site using just the URL, by simply entering the following into the internet browser:
ftp://username:password@www.sitename.com

Give that a try with your ftp username and password, and site name. It will load your FTP and log you in.

This alone you could use to log in automatically, but we want it to open in windows explorer automatically as well.

So now if you copy that above address into your start menu search box, and wait for the one internet file to be found, you can hold Alt, and then drag that file to your desktop to create a shortcut.

The link on your desktop will now open your FTP in windows explorer, and will log you in automatically every time.

You can then rename it to something more meaningful, and then you’re set! No more using your browser to access your FTP, and no more needing to log in each time.

This is an easy one, but I thought I would show it anyway.

Basically when I first started using Windows 7, it took a while to get used to the combined program icons on the taskbar, so I thought I would show this quick way to make it a bit more familiar for those of you that prefer the XP style taskbar.

To make the change, right click an empty part of the taskbar, and select Properties.

Under where it has Taskbar buttons, you can select ‘never combine’, which will make each window its own item on the taskbar, instead of grouping windows together.

You can also choose to check the ‘use small icons’ checkbox, which will make the taskbar not quite as thick as usual, and more like XP.

Click ok, and then your takbar will look like this:

Simple. As you can see each of the 2 internet explorer windows have their own items on the taskbar, and each item has a title.

Magnetism’s Dynamics CRM 2011 SketchFlow Stencils “mSketch” have just been released.

The mSketch stencils allow you to create your Dynamics CRM 2011 customizations using the stencils and Expression Blend 4, to create ‘sketchy’ forms that your customers can interact with, to give you important feedback that will save you development time and money.

Check out the mSketch product page to view some screenshots, or to find out more information:  http://www.magnetism.co.nz/solutionscasestudies/solutions/msketch.aspx

Update Rollup 14 for Microsoft Dynamics CRM 4.0 has been released, you should download it and upgrade now. http://bit.ly/bHtrKX