Pnpjs: sp.web opens root site and not current sub web

Created on 5 Jan 2019  路  3Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [x] Bug
  • [x] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [1.2.7]

Please specify what version(s) of SharePoint you are targeting: [2013]

Expected / Desired Behavior / Question

When in a subsite (http://mysp/sites/rootsite/subsite) that contains a list (mylist) the following line of code should successfully retrieves the items from the list:
sp.web.lists.getByTitle('mylist').items.get()
And the http request should look something like this
http://mysp/sites/rootsite/subsite/_api/web/lists/getByTitle('mylist')/items

Observed Behavior

When in a subsite (http://mysp/sites/rootsite/subsite) that contains a list (mylist) the following line of code returns a 404 error (list does not exist in the current web)
sp.web.lists.getByTitle('mylist').items.get()
And the http request looks like this
http://mysp/sites/rootsite/_api/web/lists/getByTitle('mylist')/items

As you can see the request completely disregards the current site path and uses the root site. I can get around this by creating a new Web object and hardcoding the url but this is obviously not a solution.

This seems like a rather big oversight, which makes me wonder if I'm just not using the library correctly, or perhaps it doesn't support this scenario (hence marking this as a question as well)

Steps to Reproduce

Pretty much what's been described above. I'm using this within an Angular 7 solution. The function looks like below. it's got some smarts around sorting, expanding, rowlimit etc, but I've omitted those for brevity
getAllListItems(params: PnPParams): Promise<any> { const call = this.web.lists.getByTitle(params.list).items; ... return call.get() }

Most helpful comment

Nice! No problem. Glad it helped 馃挭

All 3 comments

Hi @andrespinzon
Have you had a look at the documentation here and done the setup part? 馃榾

Awesome. Completely missed the baseUrl setting. I knew the issue was too basic to be missed, it had to be me ;) Thanks for the quick reply @simonagren

Nice! No problem. Glad it helped 馃挭

Was this page helpful?
0 / 5 - 0 ratings