Skip to main content

Rest API Curd Operations

Reference urls

https://www.codeproject.com/Articles/990131/CRUD-operation-to-list-using-SharePoint-Rest-API
https://social.technet.microsoft.com/wiki/contents/articles/33795.sharepoint-2013-crud-operation-on-list-items-using-rest-api-services.aspx

Retrive LIst Items


function retriveListItem() 

03.   
04.    $.ajax 
05.    ({ 
06.        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('companyInfo')/items?$select=Company,Industry", 
07.        type: type, 
08.        data: data, 
09.        headers: 
10.        
11.            "Accept": "application/json;odata=verbose", 
12.            "Content-Type": "application/json;odata=verbose", 
13.            "X-RequestDigest": $("#__REQUESTDIGEST").val(), 
14.            "IF-MATCH": "*", 
15.            "X-HTTP-Method": null 
16.        }, 
17.        cache: false, 
18.        success: function(data)  
19.        
20.            $("#ResultDiv").empty(); 
21.            for (var i = 0; i < data.d.results.length; i++)  
22.            
23.                var item data.d.results[i]; 
24.                $("#ResultDiv").append(item.Company + "\t" + item.Industry + "<br/>"); 
25.            
26.        }, 
27.        error: function(data) 
28.        
29.            $("#ResultDiv").empty().text(data.responseJSON.error); 
30.        
31.    }); 


Create List Item


function AddListItem() 
02.
03.    var industryVal = $("#Industry").val(); 
04.    var Company = $("#Company").val(); 
05.    $.ajax 
06.        ({ 
07.        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('companyInfo')/items", 
08.        type: "POST", 
09.        data: JSON.stringify 
10.        ({ 
11.            __metadata: 
12.            
13.                type: "SP.Data.TestListItem" 
14.            }, 
15.            Company: Company, 
16.            Industry: industryVal 
17.        }), 
18.        headers: 
19.        
20.            "Accept": "application/json;odata=verbose", 
21.            "Content-Type": "application/json;odata=verbose", 
22.            "X-RequestDigest": $("#__REQUESTDIGEST").val(), 
23.            "X-HTTP-Method": "POST" 
24.        }, 
25.        success: function(data, status, xhr) 
26.        
27.            retriveListItem(); 
28.        }, 
29.        error: function(xhr, status, error) 
30.        
31.            $("#ResultDiv").empty().text(data.responseJSON.error); 
32.        
33.    }); 
34.}



Update List Item



function updateListItem() 
02.
03.    var industryVal = $("#Industry").val(); 
04.    $.ajax 
05.    ({ 
06.        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('companyInfo')/items(7)", // list item ID 
07.        type: "POST", 
08.        data: JSON.stringify 
09.        ({ 
10.            __metadata: 
11.            
12.                type: "SP.Data.TestListItem" 
13.            }, 
14.            Industry: industryVal 
15.        }), 
16.        headers: 
17.        
18.            "Accept": "application/json;odata=verbose", 
19.            "Content-Type": "application/json;odata=verbose", 
20.            "X-RequestDigest": $("#__REQUESTDIGEST").val(), 
21.            "IF-MATCH": "*", 
22.            "X-HTTP-Method": "MERGE" 
23.        }, 
24.        success: function(data, status, xhr) 
25.        
26.            retriveListItem(); 
27.        }, 
28.        error: function(xhr, status, error) 
29.        
30.            $("#ResultDiv").empty().text(data.responseJSON.error); 
31.        
32.    });

Delete List Item

function deleteListItem() 
02.
03.    $.ajax 
04.    ({ 
05.        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('companyInfo')/items(7)", 
06.        type: "POST", 
07.        headers: 
08.        
09.            "X-RequestDigest": $("#__REQUESTDIGEST").val(), 
10.            "IF-MATCH": "*", 
11.            "X-HTTP-Method": "DELETE" 
12.        }, 
13.        success: function(data, status, xhr) 
14.        
15.            retriveListItem(); 
16.        }, 
17.        error: function(xhr, status, error) 
18.        
19.            $("#ResultDiv").empty().text(data.responseJSON.error); 
20.        
21.    }); 

Comments

Popular posts from this blog

Sharepoint Interview questions

What is Microsoft Windows SharePoint Services? How is it related to Microsoft Office SharePoint Server 2007? Windows SharePoint Services is the solution that enables you to create Web sites for information sharing and document collaboration. Windows SharePoint Services -- a key piece of the information worker infrastructure delivered in Microsoft Windows Server 2003 -- provides additional functionality to the Microsoft Office system and other desktop applications, and it serves as a platform for application development. Office SharePoint Server 2007 builds on top of Windows SharePoint Services 3.0 to provide additional capabilities including collaboration, portal, search, enterprise content management, business process and forms, and business intelligence. What is Microsoft SharePoint Portal Server? SharePoint Portal Server is a portal server that connects people, teams, and knowledge across business processes. SharePoint Portal Server integrates information from various systems into o

SharePoint 2010 Branding: Change site actions and welcome menu arrows

Here's how you can do it. Hide the image and give our custom image element a background image. Look Like: .ms-viewselector-arrow {     background: transparent url('/PublishingImages/images/Arrow.png') no-repeat scroll 0 0;     height: 4px; /* height of the image */     width: 5px; /* width of the image */ } .ms-viewselector-arrow img {     display: none; }

Lookup field does not showing values in sharepoint2013

SharePoint Custom Form Shows HTML as Text on Lookup Fields   When creating a custom display form on SharePoint Designer, the form displays the actual HTML instead of rendering the HTML on the lookup columns. For example, see the below image: For the lookup value issue, you need to slightly modify the XSLT of the particular field from designer and add the attribute disable-output-escaping="yes" to the field.