SOLVED

PNPJs help

%3CLINGO-SUB%20id%3D%22lingo-sub-946732%22%20slang%3D%22en-US%22%3EPNPJs%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-946732%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20currently%20using%20PNPJs%20to%20create%20an%20automated%20list%20from%20an%20Azure%20function.%20It%20loads%20perfectly%20on%20our%20main%20'Intranet'%20SharePoint%20site%20but%20for%20some%20reason%2C%20a%20list%20that%20is%20created%20on%20another%20site%20page%20won't%20update.%20Are%20there%20permission%20issues%20that%20would%20be%20causing%20this%3F%20I%20tested%20it%20on%203%20lists%20on%20the%20main%20site%20page%20and%20it%20worked%20fine.%20I%20just%20can't%20seem%20to%20figure%20it%20out.%20Any%20help%20would%20be%20massively%20appreciated.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-946732%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epnpjs%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-959760%22%20slang%3D%22en-US%22%3ERe%3A%20PNPJs%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-959760%22%20slang%3D%22en-US%22%3E%3CP%3EHey%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F292517%22%20target%3D%22_blank%22%3E%40timparsons%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20are%20you%20trying%20to%20read%20items%20from%20a%20list%20contained%20in%20a%20different%20site%20than%20the%20one%20your%20page%20is%20hosted%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-959764%22%20slang%3D%22en-US%22%3ERe%3A%20PNPJs%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-959764%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20secondary%20site%20is%20still%20part%20of%20our%20account.%20So%20we%20have%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fwww.companysharepoint.com%2Fsites%2Flist1%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.companysharepoint.com%2Fsites%2Flist1%3C%2FA%3E%20(this%20works)%3C%2FP%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fwww.companysharepoint.com%2Fsites%2Flist2%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.companysharepoint.com%2Fsites%2Flist2%3C%2FA%3E%20(this%20doesn't%20work)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-959841%22%20slang%3D%22en-US%22%3ERe%3A%20PNPJs%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-959841%22%20slang%3D%22en-US%22%3E%3CP%3EI%20see..%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20is%20it%20a%20webpart%20using%20SPFx%3F%20or%20just%20a%20script%20editor%20in%20a%20classic%20site%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnyway%2C%20if%20you%20want%20to%20query%20a%20different%20site%20using%20PnPJS%2C%20you%20have%20to%20create%20a%20new%20Web%20class%20for%20that%20site.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20in%20your%20code(assuming%20you%20a%20re%20using%20Typescript%20in%20a%20SPFx%20webpart)%2C%20you%20would%20use%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Evar%20newWeb%20%3D%20new%20Web(%22%3CA%20href%3D%22http%3A%2F%2Fwww.companysharepoint.com%2Fsites%2Flist2%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.companysharepoint.com%2Fsites%2Flist2%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%22)%3B%3C%2FP%3E%3CP%3Evar%20items%20%3D%20await%20newWeb.lists.getByTitle(%22ListName%22)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20so%20on.%20Let%20me%20know%20if%20you%20need%20any%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-960284%22%20slang%3D%22en-US%22%3ERe%3A%20PNPJs%20help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-960284%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F365643%22%20target%3D%22_blank%22%3E%40Carlos_Marins%3C%2FA%3E%26nbsp%3BI'm%20not%20actually%20using%20a%20webpart.%20I'm%20sending%20the%20data%20directly%20to%20SharePoint%20using%20a%20function%20app%20in%20Azure.%20Never%20had%20an%20issue%20before%20but%20this%20one's%20getting%20me.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

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.

4 Replies
Highlighted

Hey @timparsons 

 

So, are you trying to read items from a list contained in a different site than the one your page is hosted?

Highlighted

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)

Highlighted
Best Response confirmed by Tom Resing (Microsoft)
Solution

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.

Highlighted

@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.