0

I want to add a warning message at the top of the SP online site. For that i tried UserCustomActions using powershell, code is running without error but not working. I tried to add ribbon control that is working. I have enabled the allow script option in the admin site. Below i included the code for reference.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")

Function Add-ScriptLinkAction([Microsoft.SharePoint.Client.ClientContext]$Context,[String]$ScriptBlock,[int]$Sequence)
{

    $action = $Context.Site.UserCustomActions.Add();
    $action.Location = "ScriptLink"
    <#
    if($ScriptSrc) {
        $action.ScriptSrc = $ScriptSrc
    }#>
    
    if($ScriptBlock) {
        $action.ScriptBlock = $ScriptBlock
    }
    $action.Sequence = $Sequence
    $action.Name = "title"
    $action.Title = "title"
    $action.Update()
    $Context.ExecuteQuery()
}

$siteUrl = 'https://stginfotechchennai.sharepoint.com/sites/ProductQualityReseachCenter'
$context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
# SPO credentials
$context.Credentials = Get-SPOCredentials -UserName [email protected]

Add-ScriptLinkAction -Context $context -ScriptBlock $ScriptBlock -Sequence 1000 

1 Answer 1

0

For modern page,we need to use spfx extension to add js file to page.If your code is ok,classic page should work well.

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.