0

I use this code to get the date of the last edit of a certain list. Now I want to loop through the listitems and identify the item that was changed last, so i.e. that has the same date as the lastItemModifiedDate()

How you I do this?

Anyone?

ExecuteOrDelayUntilScriptLoaded(Initializeall, 'sp.js');
 function Initializeall()
{

 var ctx = SP.ClientContext.get_current();
 var web = ctx.get_web();
 var lists = web.get_lists();
 var list = lists.getByTitle("Sample");
ctx.load(list, "LastItemModifiedDate");
ctx.executeQueryAsync(
function() {
    var lastmodified = list.get_lastItemModifiedDate();
alert(lastmodified);
},
function() {}
);
}
</script>

1 Answer 1

0

The item that was changed last may not have the same date as the lastItemModifiedDate(). For example, the item was last changed in 9/20, you added a column to the list in 9/25, the lastItemModifiedDate() would be 9/25. They are different.

The SP.List.lastItemModifiedDate property gets a value that specifies the last time a list item, field, or property of the list was modified. So if you just changed the list description or add a column to the list, the lastItemModifiedDate() would get updated. Reference: https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-visio/jj244925(v=office.15)

And to identify the item that was changed last, you could use CAML query with jsom. For example:

var list = web.get_lists().getByTitle("List1");
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><Query><OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy></Query></View>");
items=list.getItems(camlQuery);
clientContext.load(items);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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