Archive for June 21, 2011

SharePoint 2010: Use ECMAScript to manipulate (Add/Delete/Update/Get) List Items

In SharePoint 2010 there are three different types of Client Object Model extension you can use. They are Managed Client Object Model, ECMAScript and silverlight extension.Today I’ll go through how to use ECMAScrip to manipulate list items.


How to Get ECMAScript Intellisence

When you’ll use ECMAScript library in Visual Studio, it’s possible to get intellisense for ECMAScript. There are three ways you may need to enable the intellisense:

  1. Get Intellisense in Application Page: In the case you want to put  your javascript in aspx file as inline, you need to add the following lines in the markup file. However, this will not work for webpart file. For webpart file you need to put your javascript in another js file as described in option 2. 

    <script type=”text/ecmascript” src=”/_layouts/SP.debug.js” /> 
    <
    script type=”text/ecmascript” src=”/_layouts/SP.Debug.js” /> 
    <
    script type=”text/ecmascript” src=”/_layouts/SP.Runtime.Debug.js” /> 

    <script type=”text/javascript”> 
          //you’ll get intellisense here 
    script> 

  2. Get Intellisense in js file: If you want to get intellisense in js file then you need to add the following lines in the top of the js file. As shown in the snippet below, the first reference is to MicrosoftAjax.js file. This is mandatory to have this js file reference at the top. Then I have added two other references. The two files (SP.Core.Debug.js and SP.debug.js) have basic SharePoint namespaces. However, if you need more functionalities try to add more js file reference from the path “C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/14/TEMPLATE/LAYOUTS”
    /// 
    ///
    ///

  3. Get Intellisense in webpart: To get intellisense in webpart you need to add the following two lines in the webpart ascx file: