Forum Discussion
PNPJs help
- Oct 28, 2019
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("http://www.companysharepoint.com/sites/list2 ");
var items = await newWeb.lists.getByTitle("ListName");
And so on. Let me know if you need any help.
Hey timparsons
So, are you trying to read items from a list contained in a different site than the one your page is hosted?
- timparsonsOct 28, 2019Brass Contributor
The secondary site is still part of our account. So we have:
http://www.companysharepoint.com/sites/list1 (this works)
http://www.companysharepoint.com/sites/list2 (this doesn't work)
- Carlos_MarinsOct 28, 2019Iron 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("http://www.companysharepoint.com/sites/list2 ");
var items = await newWeb.lists.getByTitle("ListName");
And so on. Let me know if you need any help.
- timparsonsOct 28, 2019Brass Contributor
Carlos_Marins I'm not actually using a webpart. I'm sending the data directly to SharePoint using a function app in Azure. Never had an issue before but this one's getting me.