Hot answers tagged

5 votes
Accepted

REST API: How to get the n most recent items in ascending order

You will need to do both the REST orderBy, and then use JavaScript to reverse the array of items in the returned results. The problem is thus: In order for the REST API to return only the n most ...
  • 3,694
5 votes

SPFX and pnp/sp : How to get all sites

Using @pnp/sp framework, you can get the list of all site collections as below: Add the below import statement: import { sp, SearchQuery, SearchResults} from "@pnp/sp"; After that, ...
  • 30.6k
4 votes

SPFX and pnp/sp : How to get all sites

Do you want all sites in the tenant, or just the sites the user has permissions to? You can use the search API to return a list of webs or site collections the user has access to. https://yourServer/...
3 votes
Accepted

SPFX save array inside item response to display in render react

Your render method is trying to render the entire assignee {assigne}, but React doesn't know how to render that object. Try changing your render to: <div className={styles.CellStyle}> {this....
  • 3,694
3 votes

Load Terms - typescript error - spfx term store taxonomy

Adding await fixed it! (microsoft should update the docs) Fix: // get terms merged with data from a term set const terms4: (ITerm & ITermData)[] = await store.getTermSetById("0ba6845c-1468-4ec5-...
  • 406
3 votes
Accepted

Query site collection property bag in SPFx extension

Looks like you are using this in Internet Explorer. You need to use a polyfill to use this in IE 11. You can download the package using npm install --save @pnp/polyfill-ie11 command. After that, ...
  • 30.6k
3 votes
Accepted

How to Get Site-users and Site-groups in SPFx using PnP-JS?

Site Users: You can get the site users using pnp.sp.web.siteUsers as given below: $pnp.sp.web.siteUsers.get().then(function(data) { var users = ""; for (var i = 0; i < data.length; i++) { ...
  • 34.7k
3 votes

PNP.js is not working in Internet Explorer. Am not using SPFx. Custom SharePoint page

Internet Explorer does not implement some of the ECMAScipt 6 types used in PnP.js. Because of this you need to use a couple ployfill libraries that implement the missing types. There are a few options ...
  • 12.4k
3 votes
Accepted

The query to field 'list/ChoiceField' is not valid."

Consider the following scenario: List A with columns: Title (Single Line Text) ColumnA (Single Line Text) ColumnB (Choice) and List B with columns: Title (Single line of Text) ColumnOne (Single ...
  • 2,940
3 votes
Accepted

Not able to insert data into TaskList In sharepoint Spfx

pnp.sp.web.lists.getByTitle("TestTask").items.add({ Title: TaskNameVal, StartDate: StartDateVal, DueDate: DueDateVal, PercentComplete: CompleteVal, AssignedToId: [AssignedToVal], ...
3 votes
Accepted

Can someone please explain what the block of code below is used for in SPFX

This is the required step while using SP PnP JS module in SPFx solution. Using this code, you set the SPFx context within the SP PnP JS library. Because SharePoint Framework provides a local context ...
  • 34.7k
3 votes
Accepted

Unable to resolve "@pnp/graph"' has no exported member named 'graph' in SPFX solution

The use of graph was changed to graphfi in PnPjs v3. https://pnp.github.io/pnpjs/transition-guide/#global-vs-instance-architecture Here's a simple example of the use of graphfi from the PnPjs ...
  • 12.4k
3 votes
Accepted

Unable to resole Module '"@pnp/sp"' has no exported member 'spfi'

spfi is available in version 3 of @pnp/sp library. So, try using PnP JS V3 in your SPFx solution. You can install specific version of @pnp/sp using command like: npm install @pnp/sp@3.6.0 Read more ...
  • 34.7k
2 votes
Accepted

Q: Create visible folder in list with SPFx

Try using something like below: const list = sp.web.lists.getById(ListId); const folderName = 'My subfolder'; list.items.add({ FileSystemObjectType: 1, ContentTypeId: '0x0120' FileLeafRef: ...
  • 34.7k
2 votes
Accepted

Using PnP.js Create() and Update() function is not working but Read() and Delete() is working

Try to use catch in the code snippet to get the exception in the code snippet like below: import { default as pnp, ItemAddResult } from "sp-pnp-js"; private PnPAddItem():void { pnp.sp.web.lists....
  • 2,513
2 votes
Accepted

How get team site groupId property from a SPFX webpart with pnp/js

I finally got the groupId with the following code: sp.web.select("AllProperties").expand("AllProperties").get().then(w => { console.log(w.AllProperties.RelatedGroupId); });
2 votes

Ho do I update property bag items in SPFX extensions?

Theoretically, you should be able to leverage the processQuery rest endpoint, and perform a query like the one below, in order to update a site custom property bag: import { SPHttpClient, ...
2 votes

How to check folder permissions using pnp/sp library in spfx web part?

You could use item.userHasPermissions(LoginName,PermissionKind) to check user permission for the folder item. Check @pnp/sp/security https://pnp.github.io/pnpjs/sp/security/
  • 4,231
2 votes

sp-pnp-js gives error when building TypeScript project

I finally got this working. I deleted the node modules and run npm install to retrieve the modules according to package.json. I did try that several times before still getting the same error, but this ...
  • 343
2 votes
Accepted

Pnp JS getting data from list

Need to set up correct spfxContent like this in WebPartName.ts: public onInit(): Promise<void> { return super.onInit().then(_ => { // other init code may be present sp.setup({ ...
  • 2,513
2 votes

Not able to insert data into TaskList In sharepoint Spfx

AssignedTo field expects the ID of person/user and not email address. You need set this field like: AssignedToId: 3 Where 3 is ID of user. Additional Reference: How to get the User Principle ID based ...
  • 34.7k
2 votes

Spfx with PnP.js / Graph: How to prevent redirect to spfxsinglesignon.aspx

I am currently working on SPFx with Graph API and it doesn't require any redirection at all for authentication, it will work with the same web part context you're developing right now. Read on https://...
  • 1,220
2 votes
Accepted

How to get the file length using PnP JS?

You could get the file length like this: sp.web .getFileByServerRelativePath("/sites/test/Shared Documents/a.txt") .get() .then(file=>{ console.log(file.Length)...
  • 5,121
2 votes

Error while following Microsoft documentation on web part caching with PnPJS

I'm not that familiar with PnPJS caching so I'm not 100% sure this is the best/recommended fix, but this code change will get the sample working: import { Caching, ICachingProps } from "@pnp/...
  • 12.4k
2 votes

Facing Error Implementing CRUD operations using spfi pnpjs package

You have to provide the SPFx web part context to spfi() in your sample code. For Example: import { spfi, SPFx } from "@pnp/sp"; // ... protected async onInit(): Promise<void> { ...
  • 34.7k
1 vote

Get multiple lists Items via REST API

Inside for loop in second SharePoint REST call you need to pass the index (i) to get the Title, like below: temp = json.value[i].Title; Also, as you are using $top=1 so it will return just one item ...
  • 34.7k
1 vote

REST API: How to get the n most recent items in ascending order

We can also use caml query to get the 50 items and sorted. Below is not an exact working code, I haven't tested, but it will give you an idea to implement it. const xml = "<View><ViewFields&...
1 vote
Accepted

Dynamically Pass List item parameter using pnp js

Try Using something like below: var ItemArray = []; var internalNameOfTitleCol = "Title" var titleColValue = "Here is a dynamic value for list item Title"; var body = {}; body[internalNameOfTitleCol]...
  • 34.7k
1 vote

How to retrieve Friendy URL from Term-Driven Page with SP PnP JS

try the below code, terms.get().then((terms:ITerm[])=>{ terms.forEach((term:any)=>{ term.LocalCustomProperties._Sys_Nav_TargetUrl; console.log(term....
1 vote

Method to get term URL in taxonomy in SharePoint TermStore using PnP JS library

Check Term.LocalCustomProperties._Sys_Nav_TargetUrl My debug screenshot: Update: The interface defined in pnpsp. import { taxonomy, ITermStore, ITermSet, ITerms, ITermData, ITerm } from "@pnp/sp-...
  • 4,231

Only top scored, non community-wiki answers of a minimum length are eligible