SOLVED

Deleting Site UserCustomActions if you can't get access to the Site Collection

Iron Contributor

Oops..

Instead of pasting a plain text URL I managed to create a Site UserCuctomAction with HTML code in it.

This "script" is now executing on every page.

The result is an (Office365) SharePoint server that delivers me only blank pages.

 

Is there an easy method of resetting UserCustomActions?

6 Replies
Would it not be the easiets way to remove the custom action by deleting it using Sharepoint Designer 2013?
Its a ScriptLink (Site UserCustomAction), I have never seen those in SPD.
(My) Quickest way was to go to another Site Collection (authenticated) get the RequestDigest from the 0ffending site with a REST call and then clear out the Site Action with a REST DELETE

I now understand why Microsoft disabled these type of UserCustomActions :) But we still want one script for every (New Experience) page...

I've made the same mistake doing some testing. To fix it I wrote a small console app to list the user custom actions and pick and choose to delete them. Maybe for future reference:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using System.Security;

namespace SharePointCustomAction
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Password:");
            var password = GetConsoleSecurePassword();
            Console.WriteLine();

            using (var ctx = new ClientContext("https://tenant.sharepoint.com"))
            {
                ctx.Credentials = new SharePointOnlineCredentials("user@tenant.onmicrosoft.com", password);

                var uca = ctx.Web.UserCustomActions;
                ctx.Load(uca);
                ctx.ExecuteQuery();

                for (var i = uca.Count - 1; i > -1; i--)
                {
                    Console.WriteLine(string.Format("Delete embedded script: {0}", uca[i].Title));
                    var input = Console.ReadKey();
                    if (input.KeyChar == 'y')
                    {
                        uca[i].DeleteObject();
                    }
                    Console.WriteLine();

                }
                ctx.ExecuteQuery();

                Console.WriteLine("-----Finished------");
                Console.ReadLine();
            }
        }

        private static SecureString GetConsoleSecurePassword()
        {
            SecureString pwd = new SecureString();
            while (true)
            {
                ConsoleKeyInfo i = Console.ReadKey(true);
                if (i.Key == ConsoleKey.Enter)
                {
                    break;
                }
                else if (i.Key == ConsoleKey.Backspace)
                {
                    pwd.RemoveAt(pwd.Length - 1);
                    Console.Write("\b \b");
                }
                else
                {
                    pwd.AppendChar(i.KeyChar);
                    Console.Write("*");
                }
            }
            return pwd;
        }

    }


}

 

best response confirmed by VI_Migration (Silver Contributor)
Solution
If the page is loading, but blank because it is breaking, you can delete it in the browser's console window by scripting CSOM.

Did you try the PnP PoSH?

 

Remove-SPOCustomAction -Scope Site

Some REST calls instead of JSOM did the job

 

 

1 best response

Accepted Solutions
best response confirmed by VI_Migration (Silver Contributor)
Solution
If the page is loading, but blank because it is breaking, you can delete it in the browser's console window by scripting CSOM.

View solution in original post