Here is the detailed documentation for the SharePoint list items and their features.
There are multiple ways to update the list item, here I am sharing the REST API Code
Steps to update the SP List Item
Follow the below listed steps to update an item.
Step 1
Create one JS file or you can use the Content Editor Web Part.
Step 2
Below is the API to get the particular list item using Item ID, you can browse this URL in the browser to check whether the API is working or not.
https://sharepoint.com/_api/web/lists/GetByTitle('samplelist')/items/getbyid(1)
Note
Replace your list name with “samplelist”.
Step 3
Refer to the jQuery in your HTML file or CEWP.
Use the below code to update the item in a SharePoint list.
- 'use strict';
- ExecuteOrDelayUntilScriptLoaded(initializePage, "sp.js");
-
- function initializePage() {
- var siteURL;
- var itemsArray = [];
-
- $(document).ready(function() {
- var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";
- UpdateListItem();
- });
-
- function UpdateListItem() {
- siteURL = _spPageContextInfo.webAbsoluteUrl;
- console.log("from top nav - " + siteURL);
- var apiPath = siteURL + "/_api/lists/getbytitle(''samplelist'')/items/getbyid(1)";
- $.ajax({
- url: apiPath,
- type: "POST",
- headers: {
- Accept: "application/json;odata=verbose"
- },
- data: "{__metadata:{'type':'SP.Data.YourlistnameListItem'},Title:”Ur input "
- }
- ",
- async: false, success: function(data) {
- alert("Item updated successfully");
- }, eror: function(data) {
- console.log("An error occurred. Please try again.");
- }
- });
- }
- }
Summary
In this blog, we have explored how to update a particular item in the SharePoint list using REST API. Happy coding.