0

I want to add custom action which opens the external link and passes the current URL as a parameter. Something like: https://external.aspx?&url=https://company.sharepoint.com/sites/testSite/SitePages/Home.aspx

I add custom action with the following PS script.

$context = GetContext($webUrl)
$web = $context.Web
$userCustomActions = $web.UserCustomActions
$context.Load($userCustomActions)
$context.ExecuteQuery()

$siteAction = $context.Web.UserCustomActions.Add();
$siteAction.Group = "SiteActions";
$siteAction.Location = "Microsoft.SharePoint.StandardMenu";
$siteAction.Name = "MyAction";
$siteAction.Sequence = 1000;
$siteAction.Url = "https:\\external.aspx?&url={Source}";
$siteAction.Title = "My Action";
$siteAction.Update();

$context.ExecuteQuery();

The issue is that the {source} parameter doesn't include the home page part. It includes the site URL only. For example, if I navigate to testSite, the {Source} value will be https://company.sharepoint.com/sites/testSite.

But I need to get https://company.sharepoint.com/sites/testSite/SitePages/Home.aspx.

If I refresh the page or load the Home page specifically the {Source} parameter will contain the correct value. But when I navigate to the page via internal links it doesn't work.

Is there a way to get full URL of the loaded page without JS code?

Your Answer

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

Browse other questions tagged or ask your own question.