1

I want to get the date / time stamp for the last item was added / updated to SharePoint site using JavaScript. Is there any API in JS to do so?

Thanks.

5

Check the http://yoursite/_api/web

It will returns the attribute called "LastItemModified".

4

Just make a GET request to following URL.

{site url}/_api/web/LastItemModifiedDate

Example using jQuery

$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/LastItemModifiedDate",
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
    success: function(data) {
        console.log(data.d.LastItemModifiedDate);
    },
    error: function(error) {
        alert(JSON.stringify(error));
    }
});
  • Here is a fetch() version using ES6: let url = 'http://www.example.com/yourweb/_api/web/lists/getbytitle(\'Member Your List Name\')/LastItemModifiedDate'; fetch(url,{ method:'get', credentials:'include', headers:{ "Accept":"application/json;odata=nometadata" } }) .then(res => res.json()) .then(json => console.log(json.value)) .catch(error => console.error("Caught Error\n",error)) – D. Awesome May 16 at 15:05
2

  • Not sure why this was downvoted. It may not provide the exact answer, but it provides an opportunity to get the answer and more. – wjervis Nov 22 '16 at 13:10
  • 1
    I guess someone does not agree with "Give a SP developer a fish and (s)he will code for a day; teach a SP developer how to fish and (s)he will have a career" – Danny '365CSI' Engelman Nov 22 '16 at 14:16
1

I'm surprised nobody mentioned the difference between the LastItemModifiedDate and LastItemUserModifiedDate. The latter property was added later by Microsoft to reflect changes made by user accounts only. The former property was influenced by changes made by the system.

REST call: sites/.../_api/web/LastItemUserModifiedDate

Read about it here:

https://sharepoint.uservoice.com/forums/329214-sites-and-collaboration/suggestions/15112005-modified-dates-in-site-contents-should-reflect-con

  • How's this different from Atish answer? – Arun Vinoth Feb 9 '18 at 19:17
  • There are 2 properties, Atish only mentions the date that is also influenced by system accounts. – pursang Feb 19 '18 at 8:19
  • While both LastItemModifiedDate and LastItemUserModifiedDate can be used on the /web level, in SharePoint 2013, it appears only LastItemModifiedDate can be used with a list /_api/web/lists/getbytitle('your list')/LastItemModifiedDate – D. Awesome May 16 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.