Wednesday, February 26, 2020

Access Denied Error on Save Site as Template in SharePoint Online

To fix this problem, we need to enable custom scripts. Here is how to fix the access denied error on Save Site as Template.


  • Login to SharePoint Online Admin Center
  • Click on Settings from the left navigation >> Scroll down to "Custom Script" section
  • Set "Allow users to run custom script on personal site" and "Allow users to run custom script on self-service created sites" options. Click on "OK" to save your changes.

However, this change may take up to 24 Hours to reflect. To enable scripting on a particular site collection immediately, use this PowerShell script in SharePoint Online Management Shell.

#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SiteURL="https://crescent.sharepoint.com"

#Get Credentials to connect
$Cred = Get-Credential

#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL -Credential $Cred

#Disable DenyAddAndCustomizePages Flag
Set-SPOSite $SiteURL -DenyAddAndCustomizePages $False

Get Active Features in Site Collection using Powershell

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Variables
$SiteURL="SiteCollection URL"

#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials

#Get Site Collection Features
$SiteCollFeatures = $Ctx.Site.Features
$Ctx.Load($SiteCollFeatures)
$Ctx.ExecuteQuery()         

#Loop through each feature and get feature data
Write-host "Site Collection Features:"
ForEach($Feature in $SiteCollFeatures)
{
    $Feature.Retrieve("DisplayName")
    $Ctx.Load($Feature)
    $Ctx.ExecuteQuery()
    $Feature | Select DisplayName, DefinitionId
}

Deactivate a Feature in SharePoint Online

SharePoint Online PowerShell to Disable Feature

#Load SharePoint Online CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Function to Disable Feature in SharePoint Online
Function Disable-SPOFeature
    param ($SiteCollURL,$UserName,$Password,$FeatureGuid)
    Try 
    {     
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteCollURL)
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $Password)
        $Ctx.Credentials = $Credentials
        $Site=$Ctx.Site
 
        #Check the Feature Status
        $FeatureStatus =  $Site.Features.GetById($FeatureGuid)
        $FeatureStatus.Retrieve("DefinitionId")
        $Ctx.Load($FeatureStatus)
        $Ctx.ExecuteQuery()
 
        #Deactivate the feature if its enabled
        if($FeatureStatus.DefinitionId -ne $null)
        {
            Write-Host "Disabling Feature $FeatureGuid..." -ForegroundColor Yellow
            $Site.Features.Remove($FeatureGuid, $true) | Out-Null
            $Ctx.ExecuteQuery()
            Write-Host "Feature has been disabled on site $SiteCollURL!" -ForegroundColor Green
        }
        else
        {
            Write-host "Feature is Not Active on the Site collection!" -ForegroundColor Red
        }
    } 
    Catch
    {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
}
  
#Parameters to Activate Feature
$SiteCollURL = "SiteCollection URL"
$UserName = "UserName"
$Password = "Password goes here"
$FeatureGuid= [System.Guid] ("f6924d36-2fa8-4f0b-b16d-06b7250180fa") #Publishing Feature
$SecurePassword= ConvertTo-SecureString $Password –asplaintext –force  
 
#Disable Feature
Disable-SPOFeature -SiteCollURL $SiteCollURL -UserName $UserName -Password $SecurePassword -FeatureGuid $FeatureGuid

Wednesday, February 5, 2020

Apply Alternate Colors in Powerapps Gallery

1. Edit a gallery item row -> set the Gallery Template, Inserted Shape, or Any TextBox or Shape, to set the FILL or Colorwith: OR
2. use "TemplateFill" of gallerytemplate and add below condition
If(Mod(Value(ThisItem.ID),2)=0, Color!Aqua, Color!AliceBlue)