Walk through all elements on a form

In some cases it is required to set all attributes on a form to disabled or do some other logic like checking which attribute has been changed. To do this you do need to walk through each attribute of the CRM form. My fellow MVP Mitch Milam has posted the technique to do this more than a year ago:

The most important piece of this code is:

var iLen = crmForm.all.length;
for (i = 0; i < iLen; i++)
o = crmForm.all[i];
switch (o.tagName)
case "INPUT":
case "SELECT":
case "TEXTAREA":
case "IMG":
case "IFRAME":
if (o.id != "leadqualitycode")
o.disabled = true;

This example does set all attributes to disabled, but another option would be to replace the o.disabled = true; line with something like:

if (o.IsDirty)
alert("The value of " + o.name + " has changed.");

This allows you to determine which attributes have been changed on the form.


Bernard Grand said...

Hey Ronald !

thanks for all your precious advises and for your blog...

What exactly do you mean by "Disabled" Attributes? That they're on Read Only mode?

Ronald Lemmen said...

Hi Bernard,

With disabled I do indeed mean read only. Is there something particular you're looking for?

Bernard Grand said...

Not for the moment :)

But I'm reading your blog really often and you've already helped me in some issue at our customers.

So any information is always useful for me...

I just wanted to get any precision about this post.

Thanks again for this blog !

Vishwas said...

All I am new to CRM Server side programming, need help

My Requirement

I have an IFRAME which has a grid and a Dropdown list , which will be fired from all entites
1> If I fire the IFRAME from (for example account form) , the dropdown list has to populated with the Views the account entity has
2> based on the selection of any of the view the grid has to display the reords that the selected view has

we are developing the IFAME using EXTJS(Using Javascript),
I need to pass the data(Views to drop down of the IFRAME and Records of that corresponding view to grid) in the xml format,..

after fecthing data from the CRMSERVICE in XML format we will populate the grid ,now again we need to send data to the CRM using CRMSERVICE in XML Format

in wat way can i acheive this...

kindly please help me..