Object Expected error on Screen level customization

By | April 16, 2009

You must have experienced this error populating sometimes when you handle the screen level customizations. Mostly this problem deals with the “View mode” and “Edit Mode” of the screens. Whenever we do some screen level customizations we will always have to take into consideration the view mode and edit mode of the screens.

For example consider you write the following script with onload event on the “Company Entry Screen” to collect the value of company name in a variable.

var lc_compname= document.EntryForm.comp_name.value

Now if you will go to the company summary screen this script will produce an error as

‘document.EntryForm.comp_name’ is null or not an object

Now if you click on change button the screen will go to the edit mode and here you will not find any error for the same script. This discrimination is because we cannot get the object in the view mode by above method, but we get it in the edit mode.

Here you can change your script to handle both the modes and avoid the error as follows.

First check the entryform object, then field object and then take the value.


If(document.EntryForm)
{
If(document.EntryForm.comp_name)
{
var lc_compname= document.EntryForm.comp_name.value
}
}

Otherwise what you can do is, you can take the values using getElementByID property.