Nov 14 2017 02:50 AM - edited Nov 14 2017 03:25 AM
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-... which received no response around sync time.
Aug 02 2019 09:49 AM
@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.
Oct 22 2019 07:28 AM
@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
Oct 25 2019 08:22 AM
@Praveen_Battula Couldn't you just deploy the content types in your site design?
Oct 25 2019 09:37 AM
@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.
Oct 25 2019 10:31 AM
@Russell Gove I have tried this as option 1 long time back. But, if you want a content type inheriting from content type hub, provisioning through site design have some issues. When I define a content type, site columns with same Id's in site design script the content types are available immediately. But, when I see after few hours, the content type publishing log shows errors when it syncs from content type hub.
I also using document content types, document set content types. Publishing site features is not a possible option in Site design. So, definitely adding document set content type is not a possible way for us via site design scripts as it depends on "Document Set" site feature. (Please try with document, document set, list content types in your sandbox and let us know).
Also, tried the option 2, PnP provisioning script with just 2 content types, site columns, one page in it. But, this also created problems when I see the content type publishing log of the site.
Then I chosen option 3, wrote azure Runbook and wait for the content types sync to newly created sites before I send email to owners of the site saying site is ready. Unfortunately, I observed in my experience (last 8 months) average it took over an hour for provisioning content types to newly created sites (Our customers are now ok to wait for an hour, imagine in long run waiting for such a long time for a single site). We have a hard limit of waiting 90 minutes and then kill Runbook. So, we usually get 6-9 sites fail messages to admins as they failed to get content types from content type hub within 90 minutes.
This is so frustrating that this shouldn't be this complex. Microsoft doesn't help in some situations or don't even give some direction for these kind of issues. This is a minimal thing everyone needs that how fast we are able to create team sites is not a point, how fast we are creating a site with the correct structure we need is matters. Content type hub + Modern team sites is a disaster combination as of now.
-Praveen.
Oct 25 2019 10:42 AM
@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.
Oct 28 2019 06:07 AM
@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.
Apr 06 2020 10:29 AM
Mar 01 2022 07:19 AM
@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?