This project has moved and is read-only. For the latest updates, please go here.

SPUtility.GetSPField returns undefined when using in DispForm.aspx

Jan 22, 2015 at 7:12 AM
I was running in DispForm.aspx the following code, but was returned is undefined.
Will the GetSPField is not available in DispForm.aspx?
<script type="text/javascript" src="/sites/testing/SiteAssets/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/sites/testing/SiteAssets/sputility.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {
get_text = document.location.search;
alert(SPUtility.GetSPField('Title').GetValue());
});
</script>
Jan 25, 2015 at 7:14 PM
Right now GetSPField will work on DispForm but GetValue does not.

If you want to get the value of the field on DispForm, you can use SPUtility to get the field and jQuery to get the value:

var field = SPUtility.GetSPField('Title');
var value = field.LabelRow.down(0).next('td').getTextContent().strip();
Jan 26, 2015 at 12:31 AM
I though you run the following code, the result is only alert of "OK 1" has been displayed.
How I can get a data DispForm.aspx Once you?
<script type="text/javascript" src="/sites/testing/SiteAssets/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/sites/testing/SiteAssets/sputility.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {
 get_text = document.location.search;
 alert('OK 1');
 var field = SPUtility.GetSPField('Title'); 
 alert('OK 2');
 var value = field.LabelRow.down(0).next('td').getTextContent().strip();
 alert(value);
});
</script>
Jan 27, 2015 at 12:05 AM
Edited Jan 27, 2015 at 5:22 AM
I made changes to the GetSPField to GetSPFieldByInternalName, and "OK1" "OK2" is now displayed.
But "value" not is still displayed, it is not able to get.
<script type="text/javascript" src="/sites/testing/SiteAssets/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/sites/testing/SiteAssets/sputility.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {
 alert('OK 1');
 var field = SPUtility.GetSPFieldByInternalName('Title');     //<--change //
 alert('OK 2');
 var value = field.LabelRow.down(0).next('td').getTextContent().strip();
 alert(value);
});
</script>
I am using office365 in Japanese.
"Title" on the screen I have to display the "件名".
Does this something becomes a problem?
Jan 28, 2015 at 3:19 AM
Woops, wrong code. Try this:
<script type="text/javascript" src="/sites/testing/SiteAssets/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/sites/testing/SiteAssets/sputility.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {
 alert('OK 1');
 var field = SPUtility.GetSPFieldByInternalName('Title');     //<--change //
 alert('OK 2');
 var value = field.LabelRow.children().next().text().trim();
 alert(value);
});
</script>
Marked as answer by saori0127 on 2/1/2015 at 3:58 PM
Feb 1, 2015 at 11:58 PM
I was able to get the value in DispForm.aspx!
Thanks so much! !