Contents
How to make PNP function async in SPFX framework?
Important to notice, that in all cases, you are returning a Promise, so you can use the .then and .catch methods to do stuff with the data outside GetServiceListData. Thanks for contributing an answer to SharePoint Stack Exchange!
How to get user profile properties in PNP?
We will then make use of the below function to fetch the user profile properties of the user and display it within the web part. pnp.sp.profiles.myProperties.get () will return the current user’s profile properties which can be iterated to return the required information.
Why do I get a 404 error when generating a REST query?
Queries issued using the above code generate a 404 error as the list name (in my case SitePages) of the hosting pages library is appended to the query, As above. Thanks! Seems like you are trying a wrong Title for the library.
Where do I find ” this ” keyword in SPFX?
All the code I am using is running inside a SharePoint Framework webpart. So, when you see the ‘this’ keyword in the code, it refers to my SPFx webpart which inherits from the BaseClientSideWebPart class. Since I am calling the code from inside my webpart, I have access to ‘this’.
Is the async await function available in typescript?
The Async/Await functionality has been around since TypeScript 1.7 but back then it was only available for the ES6/ES2016 runtime. Since TypeScript 2.1, async/await works for ES5 and ES3 runtimes as well, which is very good news.
How to use async / await in SharePoint framework?
Turns out using async/await can really make your SharePoint Framework code simpler and more readable. Lets have a look at some examples and compare between using Promises and Async/Await in your code.
You may choose to use the @pnp/sp library when building your SharePoint Framework (SPFx) web parts. This library provides a fluent API to make building your REST queries intuitive and supports batching and caching.
How to get the context for PNP / pnpjs?
There are two ways to provide the SPFx context to the library. Either through the setup method imported from @pnp/common or using the setup method on either the @pnp/sp or @pnp/graph main export.
Is the oninit method available in SPFX?
Within SPFx, this is not available, or if it is, it may not be correct. So we need to rely on the context object supplied by the framework. There are two ways to ensure that you have correctly set up your requests; we use the onInit method in this example.
Is there a new version of SPFX coming out?
I can mostly look at changelogs for the answer to this one, but are there any gotchas I should know about? (might be crossing an opinion border here) SPFx version 1.4.1 is supported with 2019. This will likely not be updated to any newer version of SPFx.
How to create a new folder in SPFX?
Create a new folder for the project by using your console of choice: Run the Yeoman generator for SPFx: Enter the following values when prompted during the setup of the new project: After the scaffolding completes, lock down the version of the project dependencies by running the following command: