With CRM 2011 all JavaScript is now saved into the solution and to write the script it now has to be included in a function - people who are used to the old way of writing JavaScript may find this difficult at first, but it does get easier. While updating some JavaScript that I had written from CRM 4.0 to CRM 2011 I realised that some of it could be made dynamic with the new concept that all JavaScript is to be contained in a function and that you call this function when you wish for it to be run.
The first example is prefill a field with the value of another:
function prefill(input, output) {
Xrm.Page.getAttribute(output).setValue(Xrm.Page.getAttribute(input).getValue());
}
When you call this function you give the names of the input value (i.e. the field that has the data), and the output value (i.e. the field that you want to contain the data).
Next, is one that may be used more often which fires the onchage event of a field:
function fireOnChange(field) {
Xrm.Page.getAttribute(field).fireOnChange();
}
When you call this function you give the name of the field that you want to fire the onchange.
So as you can see all it takes is a bit of thought and of course testing and you can turn your old hard coded JavaScript and turn it into a reusable dynamic code that you can use again and again throughout out the system but also again and again on multiple systems.