How did I get the ItemId from the SharePoint list, if there is only one item shown in the DataTable?

We try to retrieve the ItemId of the ListItemId on a SharePointDataTable, but nothing works:

console.log(fd.control('SerieFunktionen').value); --> undefined
console.log(fd.control('SerieFunktionen').value[0]); --> no properties,because undefined
console.log(fd.control('SerieFunktionen').widget.dataItems()); --> shows all data items, not only the filtered one!

// SERIENAUSTATTUNG - FUNKTIONEN
var dtSerienFunktionen = fd.control('SerieFunktionen');
    dtSerienFunktionen.ready().then(function() {
        filterSerienFunktionen();
        console.log(fd.control('SerieFunktionen').value);
        console.log(fd.control('SerieFunktionen').value[0]);
        console.log(fd.control('SerieFunktionen').widget.dataItems());
});

function filterSerienFunktionen(){
        var filter = "";
        filter += "<Eq><FieldRef Name='Ger_x00e4_t_x003a__x0020_ID'/><Value Type='Lookup'>"+ deviceItemId + "</Value></Eq>";
        filter += "";
        dtSerienFunktionen.filter = filter;
        dtSerienFunktionen.refresh();
}

Any ideas how to solve this?

The system gives me always the first item before the filtering with .widget.data[0] and not the actual filtered item.

Dear @mozilla0,
You can always get List Items with pnpjs, applying your own filters, something like this:

pnp.sp.web.lists.getByTitle("Test").items.select("Title,ID").filter("Title eq 'Test' and ID eq '10'").getAll().then(function(allItems){
  console.log(allItems);
});.

More examples here - List Items - PnP/PnPjs

1 Like

I've found yesterday the same workaround :slight_smile:

            // Serie
            // https://github.com/SharePoint/PnP-JS-Core/wiki/Working-With:-Items#retrieving-lookup-fields
            pnp.sp.web.lists.getById('eb59b9b0-ce53-495d-99fd-89a4a27e3621').items.select("ID","Ger_x00e4_t/Title","Ger_x00e4_t/ID").expand("Ger_x00e4_t").filter("Ger_x00e4_t/ID eq '" + deviceItemId + "'").get().then(function(results){
                var serieInfo = results[0];
                //console.log(results[0].Id);
                fd.field('SerieId').value = serieInfo.Id;
            });
1 Like