This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 233
Working With: Features
Patrick Rodgers edited this page Jan 31, 2017
·
2 revisions
Features are used by SharePoint to package a set of functionality and either enable (activate) or disable (deactivate) that functionality based on requirements for a specific site. You can manage feature activation using the library as shown below. Note that the features collection only contains active features.
import pnp from "sp-pnp-js";
let web = pnp.sp.web;
// get all the active features
web.features.get().then(f => {
console.log(f);
});
// select properties using odata operators
web.features.select("DisplayName", "DefinitionId").get().then(f => {
console.log(f);
});
// get a particular feature by id
web.features.getById("87294c72-f260-42f3-a41b-981a2ffce37a").select("DisplayName", "DefinitionId").get().then(f => {
console.log(f);
});
// get features using odata operators
web.features.filter("DisplayName eq 'MDSFeature'").get().then(f => {
console.log(f);
});
To activate a feature you must know the feature id. You can optionally force activation - if you aren't sure don't use force.
import pnp from "sp-pnp-js";
let web = pnp.sp.web;
// activate the minimum download strategy feature
web.features.add("87294c72-f260-42f3-a41b-981a2ffce37a").then(f => {
console.log(f);
});
import pnp from "sp-pnp-js";
let web = pnp.sp.web;
web.features.remove("87294c72-f260-42f3-a41b-981a2ffce37a").then(f => {
console.log(f);
});
// you can also deactivate a feature but going through the collection's remove method is faster
web.features.getById("87294c72-f260-42f3-a41b-981a2ffce37a").deactivate().then(f => {
console.log(f);
});
Sharing is caring!