Set default value to a field in a list using Rest API in SharePoint Online/2013/2016

The same Rest API code, we can use change the default value to a list in SharePoint 2013/2016. As a developer, we should learn about SharePoint client-side development.

Set default value to a field in a list using Rest API in SharePoint

I am doing this demo in a SharePoint Online site, but you can use your on-premise site also.

Here I have a custom list name as MyChartList and in that list in SharePoint. I have a column name as MyDefaultValueColumn in the same list. In the MyDefaultValueColumn I have set a default value as Hiii like below:

Set default value to a field in a list using Rest API in SharePoint

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

<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:

Set default value to a field in a list using Rest API in SharePoint Online

You may also like below SharePoint Rest API tutorials:

Here in this SharePoint tutorial, we discussed, how to set a default value to the SharePoint list field or column using Rest API in SharePoint Online or SharePoint 2013/2016.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

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

>