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 ...
willman's user avatar
  • 3,724
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, ...
Gautam Sheth's user avatar
  • 30.9k
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/...
Mike Smith - MCT's user avatar
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 ...
Rob Windsor's user avatar
  • 12.6k
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-...
BennKingy's user avatar
  • 436
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, ...
Gautam Sheth's user avatar
  • 30.9k
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++) { ...
Ganesh Sanap - MVP's user avatar
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 ...
ThinkB4Code's user avatar
  • 2,970
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....
willman's user avatar
  • 3,724
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], ...
Tezz Chaudhary's user avatar
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 ...
Ganesh Sanap - MVP's user avatar
3 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> { ...
Ganesh Sanap - MVP's user avatar
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 ...
Rob Windsor's user avatar
  • 12.6k
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/[email protected] Read more ...
Ganesh Sanap - MVP's user avatar
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: ...
Ganesh Sanap - MVP's user avatar
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....
Jerry's user avatar
  • 2,573
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); });
fsilisque's user avatar
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, ...
Alberto S.'s user avatar
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/
Lee's user avatar
  • 4,271
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 ...
Papageno's user avatar
  • 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({ ...
Jerry's user avatar
  • 2,573
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 ...
Ganesh Sanap - MVP's user avatar
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://...
Radityo Ardi's user avatar
  • 1,343
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)...
Michael Han's user avatar
  • 5,181
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/...
Rob Windsor's user avatar
  • 12.6k
2 votes

filter a value from a list via PNP/JS and then store it in a locale variable within SPFx SharePoint Online

You are receiving array of objects as a result from your SharePoint API call. So, you will have to get the NewId from first element/object of array result. Try using this: public ReadCounterValue = ...
Ganesh Sanap - MVP's user avatar
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 ...
Ganesh Sanap - MVP's user avatar
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&...
Karthik Jaganathan's user avatar
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[...
Ganesh Sanap - MVP's user avatar
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....
Karthik Jaganathan's user avatar

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