How to set default value to a field in a list using Rest API in SharePoint Online?

How to set default value to a field in a list using Rest API in SharePoint Online?
InfoPath alternatives for form designing SharePoint

In this post we will discuss how we can change or set the default value to a field or column in SharePoint list using Rest API. I am doing this demo in a SharePoint online site. Here I have a list name as: MyChartList and in that list I have a column name as MyDefaultValueColumn. In the MyDefaultValueColumn I have set a default value as Hiii like below:

How to set default value to a field in a list using Rest API in SharePoint Online?
How to set default value to a field in a list using Rest API in SharePoint Online?

Also you can read:
– How to get alternate languages from language settings in SharePoint online using Rest API?

– Testing SharePoint 2016 or 2013 or SharePoint Online REST API using Postman

– How to send email from SharePoint Online using Rest API?

Then I have added a script editor web part in a web part page and then added the below code inside the script editor web part.

<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>

<script>

$(function(){

$(“#btnClick”).click(function(){

var requestUri = _spPageContextInfo.webAbsoluteUrl + “/_api/web/lists/getbytitle(‘MyChartList’)/fields/getbytitle(‘MyDefaultValueColumn’)”;

$.ajax({

url: requestUri,

type: “POST”,

data: “{ ‘__metadata’: { ‘type’:’SP.Field’ }, ‘DefaultValue’: ‘Hello Updated Value’ }”,

headers: {

“Accept”:”application/json;odata=verbose”,

“X-HTTP-Method”:”MERGE”,

“content-type”:”application/json;odata=verbose”,

“X-RequestDigest”:$(‘#__REQUESTDIGEST’).val(),

“If-Match”: “*”,

},

success: onSuccess,

error: onError

});

function onSuccess(data) {

alert(‘Success’);

}

function onError(error) {

alert(‘Error’);

}

});

});

</script>

<input type=”button” id=”btnClick” value=”Update Default Column Value”/>

Here Once user click on the button, then the Default value will be updated with “Hello Updated Value” which we have set inside the code. And now if you will check the default value for the particular column it will look like below:

How to set default value to a field in a list using Rest API in SharePoint Online?
How to set default value to a field in a list using Rest API in SharePoint Online?

Hope this will be helpful.

Similar SharePoint 2013 Tutorials

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply