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
$UserName="vinit@test.onmicrosoft.com"

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


$URL="https://vinit.sharepoint.com/sites/NewsCenter"
$SiteListName="Site Pages"
$Logpath="C:\\Log.txt";
$currentDate=(Get-Date).ToString();

$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 "
<View>
    <Query>
        <Where>
        <And>
            <Eq>
                <FieldRef Name='_ModerationStatus'/>
               <Value Type='ModStat'>Draft</Value>
            </Eq>
            <IsNotNull>
            <FieldRef Name='PublishDate'/>
           </IsNotNull>
           </And>
        </Where>
    </Query>
</View>"


$currentDate +"-:Query Call Success" | out-File $Logpath -Append
ForEach ($item in $getdraftItems) {
$curretDateandTime=Get-Date
if( $item.FieldValues.PublishDate -le  $curretDateandTime){
$FileName=$item.FieldValues.FileLeafRef.Replace('.aspx','')
try{
 
 Set-PnPClientSidePage  -Identity $FileName -Publish -PromoteAs NewsArticle
 $currentDate +"-:Success Promoting the Page "+$FileName | out-File $Logpath -Append
 }
 catch{
  $currentDate +"-:Error Promoting the Page "+$FileName | out-File $Logpath -Append
 }
}
}
 
Exit

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 







Monday, 21 May 2018

How to Make a SharePoint term unavailable for Tagging/List usage but available in Search Result


Problem Statement : Recently i got a requirement from Business that they do not want one of their Market region area (Term Sets) to be displayed for user selection while submitting a SharePoint List form but previous data with that region should be available for Search.

Solution :

Regions are stored in term store as below Image and available for Tagging in SharePoint List.


















User can select these region and use for the any custom list or Document Library for Tagging purpose. below is the employee region mapping where I have utilized above region temsets.

After crawling of this list data we can search "Europe" and get result item as below

Now we have requirement like "Europe" keyword should be searchable but no other item can be added with "Europe" term.

Solution Tip : if we deprecate a Term in Termset then it will be available for search and refiners but will not be available for New item addition.

lets deprecate the term, who already know how to deprecate a Term no need to look below to my blog. You people can jump to your next task.

Steps to disable the  term:

1. Go to Termstore
2. Find your Termset
3. Right click on the term which you want to deprecate (as below screenshot)

now we will check whether "Europe" is still available for tagging or not. below screenshot confirms that "Europe" is no more available for tagging in the list.




but previously added item with "Europe" should be still searchable as like below screenshot.



Most of the big SharePoint developers already might know, but may be helpful for someone.

Thanks,
Happy Office365