SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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="""">" +
            "<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>" +
ClientContext context = new ClientContext(TargetUrl);
var site = context.Site;
var populate = site.UserCustomActions.Add();
populate.Title = "PopulateDropDown";
populate.Location = "ScriptLink";
populate.ScriptBlock = // TODO 
context.Load(list, oList => oList.UserCustomActions);

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 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.

share|improve this question 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.PageC‌​omponent\', CUI.Page.PageComponent);. What is wrong? – Popov Sergei Jan 25 '13 at 15:00
up vote 0 down vote accepted

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\" );";
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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