4

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.

1 Answer 1

5

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
}
2
  • I'm effing stoopid sometimes. Update is what I was missing. Commented May 2, 2016 at 14:44
  • 1
    overworked Eric! Commented May 2, 2016 at 20:15

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.