[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) {
Xrm.Page.getAttribute(“hosk_extension”).setValue(0);
}
if (Xrm.Page.getAttribute(“hosk_revision”).getValue() == null) {
Xrm.Page.getAttribute(“hosk_revision”).setValue(0);
}
}