I have a SharePoint 2013 custom list and a requirement to load the last list item where Status = New. I first tried SPGetLastItemID with a CAML query filter – however, that method only returns items for the current user, and I need the last item where Status = New for ALL items/users.
For some reason I can’t seem to get this working (no alert box):
var LastID; function QueryLastNewStatusItem() { var clientContext = new SP.ClientContext(); var List = clientContext.get_web().get_lists().getByTitle('Tracker'); var query = new SP.CamlQuery(); var textCaml =" <View> <RowLimit>1</RowLimit> <Query> <OrderBy> <FieldRef Name='ID' Ascending='False' /> </OrderBy> <Where> <Eq> <FieldRef Name='Status' /> <Value Type='Text'>New</Value> </Eq> </Where> </Query> </View>"; query.set_viewXml(textCaml); var item = List.getItems(query); context.load(item); LastID = GetItemID(item); alert(LastID); }
I am beginner level with JavaScript and pretty new to CAML queries. I did use internal names for FieldRef Names within the query and made sure that the function is firing.