0

I have a problem. I want to add Custom action on a Sharepoint Edit form. This must be FlyoutAnchor and i want generate his content dynamically. I'm adding them throuh ClientContext object model(using C#). This is my code(part omitted):

string format = 
        @"<CommandUIExtension xmlns=""http://schemas.microsoft.com/sharepoint/"">" +
            "<CommandUIDefinitions>" +
                "<CommandUIDefinition Location=\"Ribbon.ListForm.Edit.Actions.Controls._children\">" +
                    "<FlyoutAnchor  Id=\"COB.SharePoint.Ribbon.WithPageComponent.PCNotificationGroup.Dropdown\" Sequence=\"10\" " +
                        " LabelText=\"My layuout\" Alt=\"Sample Flyout\" TemplateAlias=\"o1\" PopulateDynamically=\"true\" PopulateOnlyOnce=\"true\" PopulateQueryCommand=\"COB.PageComponent.Command.PopulateDropDown\" />" +                                
                "</CommandUIDefinition>" +
            "</CommandUIDefinitions>" +
            "<CommandUIHandlers>" +
                "<CommandUIHandler Command=\"Sample.ButtonCommand.Command\" CommandAction=\"javascript:debugger;HelloRibbon(arguments);\" />" +
                "<CommandUIHandler Command=\"COB.PageComponent.Command.PopulateDropDown\" CommandAction=\"javascript:PopulateDropDown.apply(this, arguments);\" />" +
            "</CommandUIHandlers>" +
        "</CommandUIExtension>";
ClientContext context = new ClientContext(TargetUrl);
var site = context.Site;
var populate = site.UserCustomActions.Add();
populate.Title = "PopulateDropDown";
populate.Location = "ScriptLink";
populate.ScriptBlock = // TODO 
populate.Update();
context.Load(list, oList => oList.UserCustomActions);
context.ExecuteQuery();

but I don't know what to write in TODO string. For simple button action, I can write

function HelloRibbon(a){alert(a);}

And it will be call. In that article http://www.sharepointnutsandbolts.com/2010/02/ribbon-customizations-dropdown-controls.html i founded sample code, in "2. JavaScript page component" section there is code that generate menu items dynamically. But i don't know how i must adapt this code to ClientContext object model. Thanks for help.

1
  • patrickboom.wordpress.com/tag/pagecomponent There I find the same example. But there author register population function as a page component. I'm try to do this. But when my page loaded i see error in javascript console "Uncaught ReferenceError: CUI is not defined ". It is on call COB.SharePoint.Ribbon.PageComponent.registerClass(\'COB.SharePoint.Ribbon.PageComponent\', CUI.Page.PageComponent);. What is wrong? Jan 25, 2013 at 15:00

1 Answer 1

0

solved in that thread

Registering pageComponent using ClientObjectModel

this code work

        "ExecuteOrDelayUntilScriptLoaded ( function () {" +
        "COB.SharePoint.Ribbon.PageComponent.registerClass(\'COB.SharePoint.Ribbon.PageComponent\', CUI.Page.PageComponent);" +
        "COB.SharePoint.Ribbon.PageComponent.instance = new COB.SharePoint.Ribbon.PageComponent();" +
        "COB.SharePoint.Ribbon.PageComponent.initialize()"" }, \"CUI.js\" );";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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