Forum Discussion
PNPJs help
I'm currently using PNPJs to create an automated list from an Azure function. It loads perfectly on our main 'Intranet' SharePoint site but for some reason, a list that is created on another site page won't update. Are there permission issues that would be causing this? I tested it on 3 lists on the main site page and it worked fine. I just can't seem to figure it out. Any help would be massively appreciated.
I see..
So, is it a webpart using SPFx? or just a script editor in a classic site?
Anyway, if you want to query a different site using PnPJS, you have to create a new Web class for that site.
So, in your code(assuming you a re using Typescript in a SPFx webpart), you would use:
var newWeb = new Web("www.companysharepoint.com/sites/list2 ");
var items = await newWeb.lists.getByTitle("ListName");
And so on. Let me know if you need any help.
- Carlos_MarinsIron Contributor
Hey timparsons
So, are you trying to read items from a list contained in a different site than the one your page is hosted?
- timparsonsBrass Contributor
The secondary site is still part of our account. So we have:
www.companysharepoint.com/sites/list1 (this works)
www.companysharepoint.com/sites/list2 (this doesn't work)
- Carlos_MarinsIron Contributor
I see..
So, is it a webpart using SPFx? or just a script editor in a classic site?
Anyway, if you want to query a different site using PnPJS, you have to create a new Web class for that site.
So, in your code(assuming you a re using Typescript in a SPFx webpart), you would use:
var newWeb = new Web("www.companysharepoint.com/sites/list2 ");
var items = await newWeb.lists.getByTitle("ListName");
And so on. Let me know if you need any help.