Reputation: 709
I'm creating a new list on my SharePoint site with the aid of @pnp/sp.
I create the list and create fields:
sp.web.lists.ensure("MySPListTest")
.then((ler: ListEnsureResult) => {
if (ler.created) {
const batch = sp.web.createBatch();
ler.list.fields.inBatch(batch).addText("TextField01");
ler.list.fields.inBatch(batch).addDateTime("Date");
ler.list.fields.inBatch(batch).addBoolean("Boolean",);
ler.list.fields.inBatch(bacth).addLookup("Lookup", lookupListID, lookupFieldName);
}
})
I want to add a lookup field but I don't know how to get the GUID of a list on my site.
I get the list:
let list: List = sp.web.lists.getByTitle("Trucks")
But I don't see the ID anywhere on it.
Any suggestions on how to get the GUID of a List?
Upvotes: 2
Views: 2989
Reputation: 59358
You forgot to execute the request (via get
method) to return List
properties:
let list = sp.web.lists.getByTitle(listTitle);
list.get().then(l => {
console.log("List Id: " + l.Id);
});
References
Upvotes: 3