CRM 2011 – No Default values for fields on forms – Javascript to the rescue.

[tweetmeme source=”BenHosk” only_single=false]

I was working today setting up some fields on a form and then I noticed that my plugin (auto number plugin for CRM 2011!!!) failed.

It was because I was expecting a value in a field which stored a whole number.  This number was used to specify the number of digits the counter should be padded with zeros.

The basic problem was I was trying to convert a null into an int which obviously doesn’t work.  I thought I would supply a default value for the field but then was stupified by the fact there is not default value setting in CRM 2011.  Unless you are selecting a dropdown list which you can specify a default value then any whole numbers, decimals, strings don’t have a default value setting, WHY!!

I thought maybe CRM 2011 could supply a screen like the workflow form screens which would allow you to set default values on the form.

Instead I had to put some code in the OnLoad of the form to add a zero value.  Although this isn’t really necessary because by changing a field to Business Required the user would have to put in a value before they would be able to save the form but it made it easier for the user if I already put in a zero value for them.

It seems such a basic thing for CRM 2011 not to include much like the Auto Number/counter.  Why have they included this functionality in some entities but not in all.

This is the code I put into the onload event

function OnLoad() {

//var accId = Xrm.Page.getAttribute(“hosk_clientid”).getValue();

//var candidate =  Xrm.Page.getAttribute(“hosk_candidateid”).getValue();

if (Xrm.Page.getAttribute(“hosk_extension”).getValue() == null) {



if (Xrm.Page.getAttribute(“hosk_revision”).getValue() == null) {





One thought on “CRM 2011 – No Default values for fields on forms – Javascript to the rescue.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.