Category
Please specify what version of the library you are using: 1.3.7
I'd like support for setting metadata defaults for library (updating client_LocationBasedDefaults.html in /Forms/ folder). Is this supported?
If it's not supported, I got the code ready (https://github.com/Puzzlepart/prosjektportalen/blob/master/src/js/Project/MetadataDefaults.ts) and would like to include this in pnpjs if it's okay @patrick-rodgers.
Sure, that's great. Probably as a method on folder?
That's what I thought!
The PnP-PowerShell commandlet is Set-PnPDefaultColumnValues so probably something like this?
sp.web.lists.getByTitle('Documents').rootFolder.defaultColumnValues.update({ MetadataField: "-1;#label|id" })
or just
sp.web.lists.getByTitle('Documents').rootFolder.setDefaultColumnValues({ MetadataField: "-1;#label|id" })
.. but how can we access the list/library of a folder from the folder instance @patrick-rodgers?
We might also need access to the list to ensure the ItemAdded event receiver.
We need to [LIBRARY_URL]/Forms/client_LocationBasedDefaults.html.
I like your second option setDefaultColumnValues attached to the folder object. You can use the getParent method of Queryable - but that won't necessarily work in nested folders you'd need to test it. Or you could loop on selecting the Folder's ParentFolder property - see if you can recurse up that way. Or do something with the properties object:
const f = sp.web.lists.getByTitle("Documents").rootFolder;
f.append("Properties");
const r = await f();
r Includes:
vti_x005f_listname:"{7291BDF6-B218-40C8-AF98-3011B83DF336}"
vti_x005f_listtitle:"Documents"
That should be enough to get you what you need. So far as I know all folders should have those props.
Btw. you can use REST to enable the receiver, hopefully simplifies your solution a bit. This is a raw copy from my project.
//need to construct listErUrl first, something like this
let listErUrl = `${sp.web.getList(listData[0]).eventReceivers.toUrl()}/add`
public static ensureMetaDataDefaultsEventReceiver(client: SPHttpClient, listErUrl: string): Promise<SPHttpClientResponse> {
const eventReceivePayload: any = {
eventReceiverCreationInformation: {
EventType: 10001,
Synchronization: 1,
ReceiverAssembly: 'Microsoft.Office.DocumentManagement, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c',
ReceiverClass: 'Microsoft.Office.DocumentManagement.LocationBasedMetadataDefaultsReceiver',
ReceiverName: 'LocationBasedMetadataDefaultsReceiver ItemAdded',
SequenceNumber: 1000
}
};
return client.post(listErUrl, SPHttpClient.configurations.v1, {
body: JSON.stringify(eventReceivePayload)
});
}
I'll be honest, working on this but the effort is making me question the value. It feels like adding a hacky implementation on top of an already hacky implementation. BUT I get to use some silly regex, and that can never fail - right? Right?
Haha, I understand you @patrick-rodgers. Getting this into pnpjs would make it much easier to use this kind of functionality, but you might be right about the hackyness of a solution for this.
.. you get to use some lovely regex though 馃槑
This is added and will be part of 2.0.4