This project has moved. For the latest updates, please go here.

Error: Unable to get value of the property 'Hide': object is null or undefined

Feb 17, 2011 at 6:06 AM
Edited Feb 17, 2011 at 6:09 AM

Hello there,

This is a continuation of of our discussions on this issue in Stack Overflow: How to predefine and hide a column in SharePoint NewForm and EditForm? - Stack Overflow

I have created a custom list that I am trying to pre-select a field and hide it. But even simple functions doenst seem to work. For example I am trying to hide a field:

 

<script type="text/javascript" src="../../Hidden/prototype.js"></script>
<script type="text/javascript" src="../../Hidden/SPUtility.js"></script>

<script type="text/javascript">function myFunction()

{

var myChoiceField = SPUtility.GetSPField('Status');
myChoiceField.Hide();

}

_spBodyOnLoadFunctionNames.push("myFunction");

When loading the page I get: Error: Unable to get value of the property 'Hide': object is null or undefined

Coordinator
Feb 17, 2011 at 11:33 PM

Thanks for moving the discussion.

I have a couple questions that will hopefully let me reproduce your issue:

  1. What version of SharePoint? (2007 WSS 3.0 or MOSS? 2010?)
  2. What type of a list is it? Custom list? Library?
  3. In your code above, I'm assuming you forgot to copy/past the closing </script> tag?
  4. You added the following code via SPD to the NewForm.aspx after the PlaceHolderMain?
    <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
Coordinator
Feb 17, 2011 at 11:49 PM

As an alternative, you could try the following code:

<script type="text/javascript" src="../../Hidden/prototype.js"></script>
<script type="text/javascript" src="../../Hidden/SPUtility.js"></script>
<script type="text/javascript">
Event.observe(window, 'load', function () {
	try {
		var myChoiceField = SPUtility.GetSPField('Status');
		myChoiceField.Hide();
	} catch (e) {
		if (e) {
			var msg = 'Error: ' + e.toString();
			if (!Object.isUndefined(e.message)) {
				msg += ' [Message: ' + e.message + ']';
			}
			alert(msg);
		}
	}
});
</script>

Feb 18, 2011 at 6:20 AM

Hello Kit,

Thank you very much for taking your time to look into this and apologies for not including the information in my last message.

1. WSS 3.0

2. Custom List

3. Yes, an incorrect copy/paste :P

4. Correct. I tried your alternative code as per below after the PlaceHolderMain but received "Error: [object Error] [Message: Unable to get value of the property 'Hide': object is null or undefined]":

<asp:Content id="Content1" runat="server" contentplaceholderid="PlaceHolderMain">

<script type="text/javascript" src="../../Hidden/prototype.js"></script>
<script type="text/javascript" src="../../Hidden/SPUtility.js"></script>
<script type="text/javascript">
Event.observe(window, 'load', function () {
	try {
		var myChoiceField = SPUtility.GetSPField('Status');
		myChoiceField.Hide();
	} catch (e) {
		if (e) {
			var msg = 'Error: ' + e.toString();
			if (!Object.isUndefined(e.message)) {
				msg += ' [Message: ' + e.message + ']';
			}
			alert(msg);
		}
	}
});
</script>

Coordinator
Feb 18, 2011 at 1:28 PM

Hmm, I'm probably missing something obvious.. some more questions:

  1. Status is a choice field? Single select? Multi select? Fill in?
  2. What browser? IE 6? IE 7? Firefox?
  3. Are there any other JavaScript libraries on the page that could possibly conflict? It seems like prototype might be loading OK if the error message is printing.
  4. You're using SPUtility.js 0.7?

If possible, a screenshot could be helpful but I know it isn't always possible. :)

Coordinator
Feb 18, 2011 at 1:33 PM

You might also try adding SPUtility.Debug(true); and it may give us some more information:

SPUtility.Debug(true);
var myChoiceField = SPUtility.GetSPField('Single Choice Field');

Feb 18, 2011 at 4:02 PM

1.  I have tried with a few different fields. The one above was a single select. I just tried with a single select and got Error: [object Error] [Message: 'null' is null or not an object]

2. I am using IE8. Also doesnt work in Chrome.

3. No nothing else.

4. Correct.

 

Debug error when trying with another single choice column called "IssueType": GetSPField: Unable to find a SPField named IssueType.

Same thing with a single line of text field. 

 

Again I appreciate your time and assistance!



Coordinator
Feb 18, 2011 at 8:29 PM

The only thing I can think of is that it is having trouble finding your fields. You should be using the column's display name?

Other than that, the only thing I can think of is to set up a remote desktop session sometime so I could take a look.

Jun 29, 2011 at 9:37 PM

Hello everyone

I have the same problem (unable to find field). Did someone find an answer for that problem?

Thanks for any help.

Coordinator
Jul 13, 2011 at 6:46 PM

Markus,

I wasn't able to repro regularroutine's error. Could you post your code and some information about your environment (ex: browser, sharepoint version, prototype.js version, anything you think would be helpful)?

Thanks,
Kit

Jul 13, 2011 at 8:39 PM
Edited Jul 13, 2011 at 8:42 PM

Hi Kit

Thanks for your response. My configuration is as follows:

- Prototype Version 1.6.1

- SharePoint Foundation 2010

- I did tests with IE8 and IE9 always with the same result

The script is simple:



<script type="text/javascript">
Event.observe(window, 'load', function () {
try {
SPUtility.Debug(true);
SPUtility.GetSPField('Vorname').SetValue('Hello world!').MakeReadOnly();

} catch (ex) {
alert(ex.toString());
}
});
</script>

I load the script in a content editor webpart a the end of the web form.

The error message is as follows:
createSPField: Error creating field for Vorname
message: Unable to get value of the property 'select': object is null or undefined
description: Unable to get value of the property 'select': object is null or undefined
number: 2146823281
TypeError: Unable to get value of the property 'SetValue': object is null or undefined
Thank you in advance for your help.
Markus
Coordinator
Jul 14, 2011 at 2:59 AM

Great! Thanks for posting all of that information. What type of field is "Vorname"?

From the error message, it looks like it was able to find it OK on the page but then broke trying to find the associated controls.

Jul 14, 2011 at 10:25 AM
Edited Jul 14, 2011 at 10:27 AM
Hi Kit. the type of the field is "single line of text".

Mar 29, 2012 at 1:17 PM

Hello,

I am also facing the same problem, and googling it brought me here.

I am experiencing the same issue with both SharePoint 2010 Server and SharePoint Online.

But, luckily I have found a possible workaround! 

The problem manifests only when I was using custom forms for New, Display or Edit operations. But when using this script in the original forms (NewFormDispForm, and EditForm) everything works fine.

I don't have time right now to debug the script and further investigate, so this will work for now.

Coordinator
Mar 30, 2012 at 1:12 AM

Sorry for the inconvenience! Could you elaborate on what you mean by custom forms? Did you customize them using Infopath?

Hopefully then I can reproduce this and fix the issue!

Apr 24, 2013 at 3:52 PM
Edited Apr 24, 2013 at 3:53 PM
I have the same issue - others must've found the simple answer and forgot to post back - I'm new to this utility - but the same issue.

SharePoint 2010
  • List that had custom forms - I have recreated a standard EditForm.aspx which is where this script is
  • not finding the field
SCRIPT:
 <script src="/sites/Corp/SOX/2013/SiteAssets/prototype.js" type="text/javascript"></script>
 <script src="/sites/Corp/SOX/2013/SiteAssets/SPUtility.js" type="text/javascript"></script>
 <script type="text/javascript">
 SPUtility.Debug(true);
 var myChoiceField = SPUtility.GetSPField('Reason for Test');
 var value = myChoiceField.GetValue();
 alert(value);
 </script>
ERROR:
 GetSPField: Unable to find a SPField named Reason for Test
The field "Reason for Test" is a choice field w/ 3 options.
 Display Name = Reason for Test
 Static Name = ReasonforTest
Coordinator
Apr 25, 2013 at 12:16 AM
Edited Apr 25, 2013 at 12:16 AM
PointerBrother,
This error could happen for a variety of reasons. In your case, it looks like you may be attempting to use SPUtility before your form has loaded.

Try this out:
<script src="/sites/Corp/SOX/2013/SiteAssets/prototype.js" type="text/javascript"></script>
<script src="/sites/Corp/SOX/2013/SiteAssets/SPUtility.js" type="text/javascript"></script>
<script type="text/javascript">
function MyCustomExecuteFunction()
{
    SPUtility.Debug(true);
    var myChoiceField = SPUtility.GetSPField('Reason for Test');
    var value = myChoiceField.GetValue();
    alert(value);
}
_spBodyOnLoadFunctionNames.push("MyCustomExecuteFunction");
</script>
Thanks,
Kit
Apr 29, 2013 at 2:37 PM
Edited Apr 29, 2013 at 5:05 PM
Kit - thanks for the hints - however adding that to the screen did not work. I moved the same code to a default edit form (not my custom one modified in SPD) and I couldn't get the alert to fire.

I read through some of your other documentation on getting fields to pop, and those started working - so I went with those. I've added the PreSaveAction to it - so thanks for the nice toolset.
 <script src="/sites/DEV/SOXTesting3/SiteAssets/prototype.js" type="text/javascript"></script>
 <script src="/sites/DEV/SOXTesting3/SiteAssets/SPUtility.js" type="text/javascript"></script>
 <script type="text/javascript">

 // Get the YesNoField
 var YesNoField = SPUtility.GetSPField('Evaluation Complete');
 var YesNoValue = YesNoField.GetValue();

 // Invoking the SharePoint function to validate before saving
 function PreSaveAction(){
    if(confirm("If you are ready to submit this form, click OK; otherwise click cancel to exit without completing."))      {
        alert("Thank you for submitting this form");
        YesNoField.SetValue(true)
        return true;
        }
    else {
 //     alert("This form is not complete, click OK to continue");
        YesNoField.SetValue(false)
        return true;
    }
 }
 </script>
Does this solution work on custom forms? I can only get this script to work on OOTB forms - nothing else.
Apr 29, 2013 at 3:21 PM
Edited Apr 29, 2013 at 6:11 PM
Firefox messages I get when running this on a custom form:
 TypeError: SPUtility.GetSPField(...) is null
      var StatusValue = SPUtility.GetSPField('Division').GetValue();
and
 TypeError: $(...) is null
      $("link[rel='stylesheet']").each(function()
Coordinator
Apr 29, 2013 at 6:01 PM
Great, I'm glad you were able to get it working!

Right now, it only works with out of the box forms.... not customized forms.

I'm working on the jQuery version of SPUtility right now... maybe once I have time I'll look at adding support for custom forms as well. :)