pnp / pnpjs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs
https://pnp.github.io/pnpjs/
Other
753 stars 305 forks source link

Get pages within list with specific term id #2943

Closed patrickblanc closed 6 months ago

patrickblanc commented 6 months ago

What version of PnPjs library you are using

3.x

Minor Version Number

3.23.0

Target environment

SharePoint Framework

Additional environment details

I have a specific class with internal sp object

constructor(private context: WebPartContext | ApplicationCustomizerContext) {
    this.spHttpClient = webpartContext.spHttpClient
    this.webUrl = webpartContext.pageContext.web.absoluteUrl
    this.language = webpartContext.pageContext.cultureInfo.currentUICultureName.toLowerCase()
    this.sp = spfi(getSharePointUrl()).using(SPFx(context))
  }

Question/Request

I want to get pages from pages library that have specific term id (previously used term name but not efficient when multiple terms have same name).

const taxonomyList = this.sp.web.lists.getByTitle("TaxonomyHiddenList")
const tags = await taxonomyList.items.select('Id').filter(`IdForTerm eq '${termId}'`)()
console.log(tags) 

Tags array is always empty...

const taxonomyList = this.sp.web.lists.getByTitle("TaxonomyHiddenList")
const tags = await taxonomyList.items.select('Id')()
console.log(tags) 

Still empty.

I want to be able to get the term look up id from the taxonomy hidden list and then want to filter my pages list

const pagesLibrary = this.sp.web.lists.getByTitle("Websiteseiten")
const result = await pagesLibrary.getItemsByCAMLQuery({
      ViewXml: "<View><Query><Where><In><FieldRef LookupId='TRUE' Name='SbbSiteMapTerm'/><Values><Value Type='Integer'>39</Value></Values></In></Where></Query></View>"
    })

That is quite frustrating, beacuse same query in PowerShell using PnP is working fine.

Get-PnPListItem -List "Websiteseiten" -Query "<View><Query><Where><In><FieldRef LookupId='TRUE' Name='SbbSiteMapTerm'/><Values><Value Type='Integer'>39</Value></Values></In></Where></Query></View>"

Any idea why when i do this in my typescript application I cannot get any items from hidden taxonomy list and why ?

image

And querying pages library with caml query like this

const pagesLibrary = this.sp.web.lists.getByTitle("Websiteseiten")
const result = await pagesLibrary.getItemsByCAMLQuery({
      ViewXml: "<View><Query><Where><In><FieldRef LookupId='TRUE' Name='SbbSiteMapTerm'/><Values><Value Type='Integer'>39</Value></Values></In></Where></Query></View>"
    })
    console.log(result)

Is throwing this : One or more fields are not installed correctly. Go to the list settings page.

Thank you for your hints, help !

patrickblanc commented 6 months ago

Spfi() instead of spfi(wrongurl....) solved the problem.

github-actions[bot] commented 6 months ago

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.