SOLVED

PnP Provisioning engine - Apply to list template type

%3CLINGO-SUB%20id%3D%22lingo-sub-85756%22%20slang%3D%22en-US%22%3EPnP%20Provisioning%20engine%20-%20Apply%20to%20list%20template%20type%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-85756%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20there%20a%20way%20using%20the%20PnP%20provisioning%20engine%2C%20to%20apply%20configuration%20to%20all%20lists%20of%20a%20particular%20template%20type%20in%20a%20site%3F%20i.e.%20I%20have%20a%20specific%20configuration%20that%20will%20apply%20to%20all%20document%20libraries%20in%20a%20site.%20As%20far%20as%20I%20can%20see%20all%20list%20instances%20specified%20in%20the%20template%20file%20need%20a%20hard%20coded%20name.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt'd%20also%20be%20good%20to%20be%20able%20to%20specify%20if%20a%20list%20doesn't%20exist%2C%20it%20just%20skips%20over%20that%20bit%20instead%20of%20trying%20to%20create%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-93185%22%20slang%3D%22en-US%22%3ERe%3A%20PnP%20Provisioning%20engine%20-%20Apply%20to%20list%20template%20type%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-93185%22%20slang%3D%22en-US%22%3EGenerally%20works%20pretty%20well.%20But%20what%20I've%20kind%20of%20found%20is%20that%20running%20applytemplate%20multiple%20times%20on%20the%20same%20web%20takes%20a%20while.%20I'm%20trying%20to%20find%20a%20way%20to%20dynamically%20add%20the%20existing%20lists%20in%20a%20web%20to%20the%20template%20to%20apply%20any%20required%20settings%20to%20them.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-89485%22%20slang%3D%22en-US%22%3ERe%3A%20PnP%20Provisioning%20engine%20-%20Apply%20to%20list%20template%20type%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-89485%22%20slang%3D%22en-US%22%3E...%20and%20I%20think%20I%20got%20CSOM%20bit%20too.%3CBR%20%2F%3E%3CBR%20%2F%3EOnce%20I%20have%20the%20template%20object%2C%20I%20can%20add%20the%20Parameter%20to%20that%2C%20as%20suggested%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Sites-Core%2Fissues%2F831%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-Sites-Core%2Fissues%2F831%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-89482%22%20slang%3D%22en-US%22%3ERe%3A%20PnP%20Provisioning%20engine%20-%20Apply%20to%20list%20template%20type%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-89482%22%20slang%3D%22en-US%22%3EThanks%20for%20that.%20That%20is%20pretty%20much%20the%20approach%20I'd%20come%20up%20with.%3CBR%20%2F%3E%3CBR%20%2F%3EI've%20created%20a%20provisioning%20template%20with%20the%20settings%20I%20want%20that%20has%20a%20parameter%20%22ListTitle%22%20for%20the%20ListInstance%20title%20parameter.%20It%20works%20excellent%20for%20PowerShell%2C%20which%20is%20one%20of%20the%20use%20cases%20I'm%20using%20it%20in.%3CBR%20%2F%3E%3CBR%20%2F%3EJust%20struggling%20how%20to%20do%20the%20same%20in%20CSOM.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-86112%22%20slang%3D%22en-US%22%3ERe%3A%20PnP%20Provisioning%20engine%20-%20Apply%20to%20list%20template%20type%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-86112%22%20slang%3D%22en-US%22%3E%3CP%3EI%20would%20recommend%20a%20different%20approach.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EInstead%20of%20trying%20to%20apply%20your%20changes%20with%20one%20call%20to%20the%26nbsp%3Btemplate%2C%20add%20a%20parameter%20to%20the%20template%20for%20the%20list%20name%20and%20use%20the%20parameter%20in%20the%20template%20element%20where%20it%20is%20attempting%20to%20apply%20the%20change.%20%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThen%20use%20the%20site%20context%20to%20get%20all%20lists%20in%20the%20web%20site%2C%20test%20each%20one%20for%20its%20type%20(so%20you%20are%20only%20working%20on%20Document%20Libraries)%2C%20and%20then%20apply%20the%20template%20to%20those%20that%20match%20your%20criteria%2C%20passing%20in%20the%20name%20of%20the%20%22current%22%20doc%20lib.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBasically%2C%20loop%20through%20all%20the%20lists%20in%20your%20site%2C%20calling%20applytemplate()%20multiple%20times%2C%20once%20for%20each%20doc%20lib%20you%20want%20to%20change.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-85853%22%20slang%3D%22en-US%22%3ERe%3A%20PnP%20Provisioning%20engine%20-%20Apply%20to%20list%20template%20type%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-85853%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20could%20create%20a%20extention%20to%20your%20pnp%20project%20which%20genericly%20changes%20the%20settings%20of%20your%20lists.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Is there a way using the PnP provisioning engine, to apply configuration to all lists of a particular template type in a site? i.e. I have a specific configuration that will apply to all document libraries in a site. As far as I can see all list instances specified in the template file need a hard coded name.

 

It'd also be good to be able to specify if a list doesn't exist, it just skips over that bit instead of trying to create it.

5 Replies
Highlighted

You could create a extention to your pnp project which genericly changes the settings of your lists.

Highlighted
Best Response confirmed by Paul Quirk (Occasional Contributor)
Solution

I would recommend a different approach.

 

Instead of trying to apply your changes with one call to the template, add a parameter to the template for the list name and use the parameter in the template element where it is attempting to apply the change.  

 

Then use the site context to get all lists in the web site, test each one for its type (so you are only working on Document Libraries), and then apply the template to those that match your criteria, passing in the name of the "current" doc lib. 

 

Basically, loop through all the lists in your site, calling applytemplate() multiple times, once for each doc lib you want to change.

Highlighted
Thanks for that. That is pretty much the approach I'd come up with.

I've created a provisioning template with the settings I want that has a parameter "ListTitle" for the ListInstance title parameter. It works excellent for PowerShell, which is one of the use cases I'm using it in.

Just struggling how to do the same in CSOM.
Highlighted
... and I think I got CSOM bit too.

Once I have the template object, I can add the Parameter to that, as suggested here: https://github.com/SharePoint/PnP-Sites-Core/issues/831
Highlighted
Generally works pretty well. But what I've kind of found is that running applytemplate multiple times on the same web takes a while. I'm trying to find a way to dynamically add the existing lists in a web to the template to apply any required settings to them.