Remove existing DataRows when provisioning list Data Rows using Office Dev PnP Provisioning

Bronze Contributor

Great that it's possible to deploy DataRows for lists using the #provisioningtemplate. Can this be extended, so it's possible to delete existing DataRows? This is useful when I'm applying a provisioningtemplate to a site for the second time.


This could something like:

<pnp:DataRows RemoveExistingDataRows="true">
  <pnp:DataRow>
    ...
  </pnp:DataRow>
  <pnp:DataRow>
    ...
  </pnp:DataRow>
</pnp:DataRows>

 

I'm now using the Office Dev PnP PowerShell command to delete the items using:

Get-SPOListItem -List Tasks | ForEach-Object { $_.DeleteObject() }

It would be great if this call is not needed via PowerShell anymore, but can be realized directly inside a provisioning template.

2 Replies

You could write your own PnP provisioning extensibility provider to extend the engine in case you want a pure code based solution. See https://github.com/OfficeDev/PnP/tree/dev/Samples/Provisioning.Extensibility.

 

One of the design tenets of the engine is that we're not deleting data...

Isn't the general idea that what you export is what you import. So that the .pnp file becomes a tmeplates that is saved from the site.

 

When you use Datarows you will have manually added that to the xml file. (I've done the same in past projects)

 

Therefore deleting the items with additional PowerShell isn't a bad idea.

 

I'm comparing this a bit to the issue that I resolved where only the welcome page is exported. To recreate all the other pages in my site I created an additional xml called pages.xml. In this file I specify the page details and the web parts on it.

 

Maybe for your datarow issue in lists you could do the same. Specify the lists where you want to clear the data from (assuming that you don't want to do this for every list) and then get some PowerShell to clear the lists from their items if needed.

 

If've not tested this but if you are just after not duplicating the items you could include a unique field in your datarows (e.g. ID) so that the uniqueness will make the recreation of the items fail.