Forum Discussion
Modern Sites - Content Type Hub Site Policy initial sync time
Hi,
I'm using PnP Partner Pack to provision sites and apply site policies using the PnP Template XML (<pnp:SitePolicy>) once the site is provisioned. The site policies have been created in the content type hub. For classic sites this is fine as the content type hub is hooked up as soon as the site is ready, but for modern sites this is done later on. I was hoping I could just intermittently check for the policies being pulled down to the site and apply the policy when they are as often I was seeing this occur 5-10 minutes after a site was created. But occasionally I've seen it take 2 hours+.
I'm guessing there is a "worst case" time given for how long this can take in SP Online a bit like items being found by search. I notice in Joanne Kleins blog post there is mention of syndication of updates taking 24-48 hours, is this the worst case time for initial hook up of a site to the content type hub? I've also seen a reply on stack exchange of 4 hours for the Content Type Hub Subscriber Timer Job.
I'm also guessing there is currently no way of opting into this being hooked up any quicker. Clearly the classic sites wait, but I guess to speed up provisioning of modern they opt out of doing this. I know you can programmatically ask for a refresh of the CTs in the hub by clearing out the property bag property "metadatatimestamp" (which is the programmatic equivalent of clicking "Refresh all published content types on next update"), but for my scenario it's the initial pull down I'm waiting on.
Any info appreciated.
Thanks.
EDIT - admittedly this is probably a duplicate of the second question on this post https://techcommunity.microsoft.com/t5/SharePoint/0365-group-Content-type-publishing-hubs-unable-to-refresh-all/m-p/75733/highlight/false#M7145 which received no response around sync time.
- Praveen_BattulaCopper Contributor
Adam Wildash This is a known issue since modern sites released. Content types will not be synced immediately to newly created sites in modern sites. It takes anywhere from 10 mins to 4 hrs in my observation.
Today, we have written a script to keep looking (wait and loop every 20 minutes) for content types available or not in site collection in post-site-creation script. We are using content types from content type hub, as site design script provision all lists and libraries which EOD uses content types. So, once content types are available we are adding content types to libraries and lists.
-Praveen.
- pseudoCopper Contributor
Praveen_Battula Greetings, I am facing the same situation, has there been any development in being able to force a sync? or can you share whatever code you used to check and update when...? thank you for any help
- Praveen_BattulaCopper Contributor
pseudo Please see my latest reply.
I have used azure runbook (pnp powershell) to complete this.
We are using site design script for provisioning lists, libraries, add to hub site and deploy extensions to the newly created site.
We are using Microsoft Flow to do some business logic on newly created site and then if all good, calling Azure Runbook from Microsoft flow.
In Azure Runbook, we are checking content types availability. If content types are not available yet, then we are sleeping for 10 minutes and calling a recursive function. We are waiting 6 times (60 minutes) and check every 10 minutes availability of content types. If yes, then we are adding content types to libraries. Once all good, we are sending response back to Flow.
Flow is reading response from Azure Runbook and send email to site owners saying Site is Ready. In case if the content types are not available then we are sending email to help desk to take a look at the issue (manually).
Please let me know if you need any specific help in understanding above implementation.
Sample code to understand:
function Check-ContentTypesAvailable {
$ctype = $libraryMapping[0].contentType.split(',')
$contentType = Get-PnPContentType -Identity $ctype[1]
if(!$contentType){
if($checkContentTypesAttempts -lt 6) {
Write-Warning "Content type is null, sleeping for 10 mins."
sleep 600
$checkContentTypesAttempts++
Check-ContentTypesAvailable
}
else {
$global:errorMessage = "Made 6 attempts. Still content types are not available."
Write-Error $global:errorMessage
$global:errorCount++
return
}
}
else{
Write-Verbose "Content types available"Write-Verbose "`t 4.2. Add content type to libraries - Starting."
$libraryIndex = 0
ForEach($library in $libraryMapping){
$libraryIndex++
$cts = $library.contentType.split(',')
ForEach($ct in $cts){
try{
Add-PnPContentTypeToList -List $library.name -ContentType $ct -DefaultContentType | Out-Null
}
catch{
$global:errorCount++
$global:errorMessage = "Adding content type to $library failed."
Write-Error $global:errorMessage
}
}
Write-Verbose "`t `t 4.2.$libraryIndex. Added content type $library"
}
$global:contentTypesAvailable = $true
Write-Verbose "`t 4.2. Add content type to libraries - Completed."
}
}The input of the librarymapping looks like below:
$libraryMapping =
@(
[pscustomobject]@{name="Lib1";contentType="ct1,ct2"},
[pscustomobject]@{name="Lib2";contentType="ct3"}
[pscustomobject]@{name="Lib3";contentType="ct4"}
)Just for you, composed this function to understand. Please test yourself for any syntax issues.
thanks
-Praveen.
- Russell GoveIron Contributor
Praveen_Battula Couldn't you just deploy the content types in your site design?
- pseudoCopper Contributor
Russell Goveso I have pnp scripted the site creation for a new modern site... I have also scripted adding the content type from existing types... however it doesn't become and existing content type until 4-12 hours after the site is created. (content type doesn't technically exist)
one would suppose I could create a new type, but in the case of ever editing it, you would want it to inherit properties across enterprise I would assume. so was looking for w away to force the sync so content type is instantly available (or quickly available)
everything I have read this is not possible... but as time passes who knows.
- praveenbattulaCopper Contributorjust a quick update: Looks like Microsoft is planning to release modernized content type gallery, term store this quarter. See more details here:
https://techcommunity.microsoft.com/t5/microsoft-sharepoint-blog/modernizing-sharepoint-managed-metadata-services-mms/ba-p/1277450- RickSanchezCopper Contributor
praveenbattula I dont think the issue has been resolved? Even if it's quicker available in the UI. Doing it through scripting still gives a lot errors.. Anyone else having the same issue?