Working in SharePoint 2013. Trying to add a UserCustomAction to an EditForm.
List custom = web.Lists.GetByTitle("custom");
UserCustomActionCollection UserActions = custom.UserCustomActions;
ctx.Load(UserActions);
ctx.ExecuteQuery();
UserCustomAction CreateEmailAction = custom.UserCustomActions.Add();
CreateEmailAction.RegistrationId = "{0BF934CE-0175-4E9D-BA6A-F58B7B1F2A89}";
CreateEmailAction.RegistrationType = UserCustomActionRegistrationType.List;
CreateEmailAction.Title = "HT Edit form Create email";
CreateEmailAction.Location = "CommandUI.Ribbon.EditForm";
CreateEmailAction.Group = "Actions";
CreateEmailAction.Sequence = 1000;
CreateEmailAction.CommandUIExtension = Properties.Resources.ribbon_editmeeting;
CreateEmailAction.Update();
ctx.ExecuteQuery();
XML code:
<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
<Button Id="Ribbon.Documents.New.RibbonTest"
Command="Notify"
Sequence="0"
Image16by16="/_layouts/images/NoteBoard_16x16.png"
Image32by32="/_layouts/images/NoteBoard_32x32.png"
Description="Uses the notification area to display a message."
LabelText="Notify hello"
TemplateAlias="o1"/></CommandUIDefinition></CommandUIDefinitions>
Fails with the error 'Microsoft.SharePoint.Client.ServerException occurred HResult=0x80131500 Message=Setting this property is not supported. A value of {8F405B73-81C3-47C9-A07F-8899B57F09F9} has already been set and cannot be changed.'
If I omit the RegistrationID line, the code completes successfully, but no action is created.
1) The RegistrationID refers to the List that the action will be registered to. Since you are adding the custom action through the line:
UserCustomAction CreateEmailAction = custom.UserCustomActions.Add();
(where custom references the List) that part is done for you. By attempting to reset the value, you through the error.
2) using the location for "List Item Menu" the action works:
UserCustomActionCollection UserActions = custom.UserCustomActions;
ctx.Load(UserActions);
ctx.ExecuteQuery();
UserCustomAction CreateEmailAction = custom.UserCustomActions.Add();
CreateEmailAction.Title = "HT Edit form Create email";
CreateEmailAction.Location = "EditControlBlock";
CreateEmailAction.Group = "Actions";
CreateEmailAction.Sequence = 1000;
CreateEmailAction.Update();
ctx.ExecuteQuery();
So I think the second part if it not being created has to do with creating the UI to trigger the button. There may be more resources to add a button to the edit form here: https://sharepoint.stackexchange.com/q/103696 and here: https://sharepoint.stackexchange.com/q/133088
3) The custom action basically invokes a URL, so you also need to set the URL of the action that will be activated. This could be a workflow as well. For example:
sendDocumentAction.Url = String.Format("~site/_layouts/15/wfstart.aspx?List={{ListId}}&ID={{ItemId}}&SubscriptionID={0}", newSubscription.Id);
Where newSubscription is the Workflow Subscription to be activated
User contributions licensed under CC BY-SA 3.0