Forum Discussion
Modern Sites - Content Type Hub Site Policy initial sync time
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.
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_BattulaOct 25, 2019Copper 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.
- pseudoOct 28, 2019Copper Contributor
Praveen_Battula- no worries, I am looking for a sync for the existing site content types for immediate access. I have a workaround to enable them after 12 hours. through a scheduled job, this is just to get request turned around near immediately.