3

I'm trying to update a UserCustomAction that is set on a web. I am trying to update the ScriptSrc url of the action to include a query string parameter, ?rev=1, but it does not seem to be taking. mainly this is to "refresh" a custom action if the underlying JavaScript file is updated. The main portion of my function looks like this:

Begin {
        $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
        $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName,$credential.Password)
        if($ActionType -eq "Site"){
            $site = $context.Site
        }
        else{
            $site = $context.Web
        }
        $customActions = $site.UserCustomActions
        $context.Load($customActions)         
    }
    Process {
        try{
            $customActions.GetById($Id).ScriptSrc = $ScriptSrc
            $context.ExecuteQuery()
            Write-Host "CustomAction $Id updated" -ForegroundColor Green
        }
        catch{
            Write-Host -ForegroundColor Red $_.Exception.Message
        }
    }
    End {
        $context.Dispose()
    }

When passing in my parameters for an existing UserCustomAction, it says it was successful, but the query string is not set. If I create the UserCustomAction initially with a query string parameter, it takes. It also says that ScriptSrc is a settable property, so I'm not understanding why it isn't updating in this case.

3

Should you not do UserCustomAction.Update() after you set the new script source? (also you may want to store the action in a variable:

try{
    $theAction = $customActions.GetById($Id)
    $theAction.ScriptSrc = $ScriptSrc
    $theAction.Update()
    $context.ExecuteQuery()
    Write-Host "CustomAction $Id updated" -ForegroundColor Green
}
catch{
    Write-Host -ForegroundColor Red $_.Exception.Message
}
  • I'm effing stoopid sometimes. Update is what I was missing. – Eric Alexander May 2 '16 at 14:44
  • 1
    overworked Eric! – Mike May 2 '16 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.