Tuesday 14 August 2018

Schedule Publishing of Modern Site Pages in Sharepoint online Office 365

Problem Statement : As we are aware we don't have any Schedule Publishing features for Modern SharePoint Pages. Still user wanted to have scheduled Publishing of News Article.

Solution:  We have created a custom Column Property name called PublishDate for Site Pages Library as below screen shot.

Schedule Publishing of Modern Site Pages in Sharepoint online Office 365

we have asked News Publishers to follow the below steps for Schedule Publishing if they want to do.

Step 1 : Create a Site page

Step 2 :  Edit the content as they wanted

Step 3 :  save the article as draft

Step 4 :  edit the site page properties and update the Column "PublishDate" with their desired date and Time of the Publishing as shown in above pic.

Task Scheduler : we run a scheduler at every 15 min to check whether any Saved Draft article or News is available for Publishing. scheduler run a Powershell script as below.

# A script to check for all draft site pages where Published date is non empty
# we will publish those pages and promote as new article

# Created 26-June-2018  vinit kumar

# Check that we are connected to sharepoint Online

$Password = ConvertTo-SecureString  "Password" -AsPlainText -Force

$SiteListName="Site Pages"

$SPCredentials = New-Object -typename System.Management.Automation.PSCredential -argumentlist $UserName,$Password

$currentDate +"-:Connect Start" | out-File $Logpath -Append
Connect-PnPOnline -Url $URL -Credentials $SPCredentials
$currentDate +"-:Connect Ends" | out-File $Logpath -Append

$getdraftItems = Get-PnPListItem -List $SiteListName  -Query "
                <FieldRef Name='_ModerationStatus'/>
               <Value Type='ModStat'>Draft</Value>
            <FieldRef Name='PublishDate'/>

$currentDate +"-:Query Call Success" | out-File $Logpath -Append
ForEach ($item in $getdraftItems) {
if( $item.FieldValues.PublishDate -le  $curretDateandTime){
 Set-PnPClientSidePage  -Identity $FileName -Publish -PromoteAs NewsArticle
 $currentDate +"-:Success Promoting the Page "+$FileName | out-File $Logpath -Append
  $currentDate +"-:Error Promoting the Page "+$FileName | out-File $Logpath -Append

Script check if article Moderation Status  is "Draft" and Current Date and Time is greater than the Published date then using Modern Client side page script first we publish the Article and then Promote as News.

This is a workaround since scehdule Publishing is not available currently but might available in future.

If you like you can use this solution or share.

Happy Modern site 

No comments:

Post a Comment