Comments (11)
Hi @jimmywim,
Not an issue to add this enhancement. Actually, I already did it in a local branch and in a process of testing before PR.
Thanks for enhancement suggestion offer!
from pnpjs.
Sorry, @jimmywim - did you mean "now" working or "not" working?
If there is no special functionality on that endpoint I am not sure we need to explicitly extend the Web object to include it. However if there is something we can support that will help, please let us know.
What about something like getParentWeb(): Promise<Web>
?
from pnpjs.
Hi Patrick, I do mean "now" working - the same I pasted above works.
getParentWeb(): Promise<Web>
is something that I feel would be useful, and the implementation would appear to simply be the two lines:
const response = await web.select('ParentWeb').expand('ParentWeb').get();
return sp.site.openWebById(response.ParentWeb.Id);
from pnpjs.
After some tests:
ParentWeb
endpoint is not the same as having an instance of the web.
And my initial idea of adding:
/**
* Gets this web's parent web
*
*/
public get parentWeb(): Web {
return this.clone(Web, `parentWeb`);
}
to Web class failed on deep testing.
Let me elaborate a bit on this.
My idea was to add sp.web.parentWeb
returning an instance of Web
. But parentWeb
is just a set of properties and can't be chained with other usual endpoints. I.e. sp.web.parentWeb.lists
will fail, sp.web.parentWeb.select('Url')
won't return the prop.
In existing code base we can actually deal with parentWeb
in the following way:
pnp.sp.web.select('ParentWeb').expand('ParentWeb').get().then(console.log);
So... I'm not sure, do we need parentWeb as an additional get method? Any thoughts?
from pnpjs.
That method appears to get some data about the parent Web but it's not of type Web
in the code base, so doesn't have all the methods & properties on it (which is useful, and what I currently need as I'm in a recursive method trying to pull out Publishing's available page layouts - agreed that's not something to deal within Modern sites but the ability to get the full Web object for the parent might still be useful).
The object that comes back does have Id though, so we can use Site.openWebById()
on it.
from pnpjs.
A web object can be constructed using const web = new Web([web absolute url])
.
In most situations, I would use existing web URL and pop last path part out and build parent web object with full API support.
Or, as you said, site.openWebById is the case too:
(async () => {
const { ParentWeb } = await pnp.sp.web.select('ParentWeb/Id').expand('ParentWeb').get();
const { web: parentWeb } = await pnp.sp.site.openWebById(ParentWeb.Id);
const lists = await parentWeb.lists.get();
console.log(lists);
})()
.catch(console.error)
from pnpjs.
Almost.
This is a now-working example I have for recursing webs (looking for a property bag value that isn't "__inherits":
async recurseWeb(web: Web): Promise<Web> {
const bagOValues = await web.allProperties.get();
if (bagOValues[SitePropertyBagFields.AVAILABLE_PAGE_LAYOUTS]) {
const layoutsXml = bagOValues[SitePropertyBagFields.AVAILABLE_PAGE_LAYOUTS];
if (layoutsXml === "__inherit") {
const response = await web.select('ParentWeb').expand('ParentWeb').get();
const parentWeb = await sp.site.openWebById(response.ParentWeb.Id);
return this.recurseWeb(parentWeb.web);
} else {
// ... parse the xml and pull out the necessary data
}
}
}
from pnpjs.
Maybe not for merging, but for a review of the helper. Please check the PR - the implementation of getParentWeb(): Promise<{ data: any; web: Web; }>
. As openWebById
returns Web object together with the data object, I keen on keeping both.
const { data, web: parentWeb } = await web.getParentWeb();
What do you think would it be helpful?
from pnpjs.
Yep, I think that'd be perfect.
from pnpjs.
Looks like this was merged, so closing issue. Thanks!
from pnpjs.
I finally got the lists from parent web by
const results = await sp.site.rootWeb.lists.getByTitle("mylist")...
Full example:
const results = await sp.site.rootWeb.lists.getByTitle("mylist").getItemsByCAMLQuery({
ViewXml: `<View><Query>
<Where>
<And>
<And>
<Contains>
<FieldRef Name='${"Metadata_x0020_Navigation"}' />
<Value Type='TaxonomyFieldType'>Lease Agreements</Value>
</Contains>
<Contains>
<FieldRef Name='Metadata_x0020_Navigation' />
<Value Type='TaxonomyFieldType'>Graphics</Value>
</Contains>
</And>
<Eq>
<FieldRef Name='FSObjType' />
<Value Type='Integer'>0</Value>
</Eq>
</And>
</Where>
</Query></View>`,
});
from pnpjs.
Related Issues (20)
- Need help in understanding the Sharepoint Patterns and Policies. HOT 5
- Help insert Managed Metadata Data into a multivalue field HOT 3
- gettoken for another Azure APP using client id and pnpjs authenticated instance HOT 5
- SPFx Context supplied to SPFx Behavior is null or undefined HOT 2
- Parsing verbose JSON HOT 2
- Adding Excel workbook support HOT 3
- TypeError: Failed to fetch at c when trying to attach files in SPFx HOT 6
- @pnp/graph - spfx msal v3 single sign on redirect HOT 5
- copyByPath can return an unuseable object HOT 6
- Async Iterator Pattern Type Error HOT 3
- Getfilebyserverrelativeurl return corrupted file for .docx file HOT 3
- Batching multiple lists fail HOT 4
- Custom Http request to pull RateLimit-Reset header HOT 3
- Why use the .js extension in imports? HOT 3
- Email Notification delays while send email using @pnp/sp/utilities HOT 9
- Get Version History of a List Item in one request. HOT 3
- v4 - How do I get paged items using async iterator and break only when ALL items are retrieved? HOT 3
- sendEmail from property not working HOT 3
- Update Content Type from List endpoint and not web HOT 2
- Next on cached pagination request HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pnpjs.