Search This Blog

Tuesday 12 June 2012

Working with SPUtility.js in SharePoint 2010


Let me discuss the use of SPUtility.js in SharePoint 2010 with simple examples.

Populate value for the Title field automatically 

Write the following script

Approach 1:
<script src="/Shared%20Documents/prototype.js" type="text/javascript"></script>
<script src="/Shared%20Documents/SPUtility.js" type="text/javascript"></script>
<script type="text/javascript">
Event.observe(window,'load',function(){
    SPUtility.GetSPField('Title').SetValue('Hello world!');
}); </script>

Approach 2:
<script src="/Shared%20Documents/prototype.js" type="text/javascript"></script>
<script src="/Shared%20Documents/SPUtility.js" type="text/javascript"></script>
<script type="text/javascript">
function MyCustomExecuteFunction()
{
     SPUtility.GetSPField('Title').SetValue('Hello world1!');
}
_spBodyOnLoadFunctionNames.push("MyCustomExecuteFunction");</script>

To install, you’d simply place the JavaScript above into a Content Editor Web Part on your NewForm.aspx or EditForm.aspx. Take a look at the SPUtility.js Installation page for detailed instructions.

Get the Title field value in EditForm.aspx

Approach 1:
<script src="/Shared%20Documents/prototype.js" type="text/javascript"></script>
<script src="/Shared%20Documents/SPUtility.js" type="text/javascript"></script>
<script type="text/javascript">
Event.observe(window,'load',function(){
    alert(SPUtility.GetSPField('Title').GetValue());
}); </script>

You can use approach 2 also to get the value.

Reference Links:
Installation documentation:
 
Download scripts

SPUtility.js details



No comments:

Post a Comment