One of the feature requests that I receive quite often while creating custom CRM solutions is the have the ability to disable all or most of the fields on a CRM form based on data selected by the user.
I've researched this off and on for quite a while but was never really able to get a solution that I was comfortable with. Yesterday I started working on the solution in earnest and here is my solution:
1: // disable all of the fields on the form.
2: DisableFormFields = function(onOff)
3: {
4: var iLen = crmForm.all.length;
5:
6: for (i = 0; i < iLen; i++)
7: {
8: o = crmForm.all[i];
9: switch (o.tagName)
10: {
11: case "INPUT":
12: case "SELECT":
13: case "TEXTAREA":
14: case "IMG":
15: case "IFRAME":
16: if (o.id != "leadqualitycode")
17: {
18: o.disabled = onOff;
19: }
20: break
21: default:
22: break;
23: }
24: }
25: }
This code needs to be placed in the form's OnLoad event. In this example, we're working with the Lead Entity.
The DisableFormFields() function is actually attached to the OnChange event for the Lead Status Attribute. I check the value of Lead Status and call DisableFormFields(true) to disable the fields or DisableFormFields(false) to re-enable the fields.
Since disabling the entire form really wouldn't be a good idea, we need to allow the user to change their mind. As we loop through each of the form fields, we check the id of the field and as long as we don't encounter Lead Status, we set the fields disabled status to either true to disable the fields or false to re-enable them.
One Response
Xanadu
21|Oct|2008 1(CRM 4.0)
Somehow, when I use this code and then try to save a undisabled field, I get an error. The tracelog tells me that the statuscode can't become 0 (zero).
If I don't use the script everything goes fine …
Do you got a clue about what's happening in my form, for me?
Recards,
Xanadu
Leave a reply