CRM 2011 – Be careful removing fields from a form

I had written some javascript which retrieved values from a field which I was displaying on the form.

I had added an account field onto a quote product, so I could then use the account id to inject into some fetchXML in a subgrid so I only showed quote products which had only been sold to the the account selected on the quote.

I could have looked this up using a query but I thought I would add it onto the Quote Product form and pass the value using relationships.

It worked fine but as I came to release the code I thought I didn’t really need the account lookup field on the form so I took it off.

Then when testing my code it wasn’t working, so I pressed F12 and was ready to debug, except it wasn’t running my code because it was erroring whilst trying to get the account lookup field, with this error.

SCRIPT5007: Unable to get value of the property ‘getValue’: object is null or undefined

So the morale of the story is, you can only access fields in Javascript which are on the form.  The solution to this problem was to make the fields not visible.

This is logical when I stop to think about it because why would CRM load up all the variables which are not being used on the form, it would be a complete waste of time.

This was an early morning, not fully awake error but it does show you the danger of taking off variables from a form without seeing if any javascript uses those fields for something

4 thoughts on “CRM 2011 – Be careful removing fields from a form

  1. mscrmtools September 5, 2012 / 12:01 pm

    Hi Hosk!
    The best way to avoid this kind of problem is to add dependencies to attribute in each script call definition on form designer
    This way, when trying to delete an attribute from the form, a warning will be displayed


    • Hosk September 5, 2012 / 12:02 pm

      that is an excellent piece of advice

      I had totally forgot about that piece of functionality


      • Parvez Ghumra September 6, 2012 / 6:24 am

        Yep, was just going to say you could add a dependency on the attribute in your Javascript event handler function definition.

        and also , code your Javascript function such that it checks that the attribute/control object is not null before attrmpting to call getValue() on it. 🙂


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.