1) Create a column in the list with the “Date and Time” as its field type.
3) Give your list name & list column name wherever required.
<script>
var clientContext;
var web = null;
ExecuteOrDelayUntilScriptLoaded(UpdateList, 'sp.js');
function UpdateList()
{
if (SP.ClientContext != undefined && SP.ClientContext != null) {
clientContext = new SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) { var siteColl = web = siteColl.get_rootWeb();
var list = web.get_lists().getByTitle('List Name');
var query = SP.CamlQuery.createAllItemsQuery();
this.listItems= list.getItems(query);
clientContext.load(this.listItems, 'Include(Column Name)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess), Function.createDelegate(this, this. onListItemsLoadFailed));
}
}
}
function onListItemsLoadSuccess()
{
var listEnumerator = this.listItems.getEnumerator();
while(listEnumerator.moveNext())
{
var todaysDate = new Date();
var oListItem = listEnumerator.get_current();
var currentdate = oListItem.get_item('Column Name');
oListItem.set_item('DueDate',todaysDate);
oListItem.update();
}
clientContext.executeQueryAsync(Function.createDelegate(this, this.ListItemsUpdateSuccess), Function.createDelegate(this, this.ListItemsUpdateFailed));
}
function onListItemsLoadFailed ()
{
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
{
alert('Success ');
}
function ListItemsUpdateFailed()
{
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());}