is there any ways to register PageComponent using client object model? I want to add custom action on the edit form with dynamically populating FlyoutAnchor. But when page has been loaded i recieve following error "Uncaught ReferenceError: CUI is not defined ". I think this is because my page component was not loaded. I'm trying to do this by this code(C#):
ClientContext context = new ClientContext(TargetUrl);
var site = context.Site;
var populate = site.UserCustomActions.Add();
populate.Title = "PopulateDropDown";
populate.Location = "ScriptLink";
populate.ScriptBlock =
"Type.registerNamespace(\'COB.SharePoint.Ribbon.PageComponent\');" +
"COB.SharePoint.Ribbon.PageComponent = function () {" +
"COB.SharePoint.Ribbon.PageComponent.initializeBase(this);" +
"};" +
"COB.SharePoint.Ribbon.PageComponent.initialize = function () {" +
"ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, COB.SharePoint.Ribbon.PageComponent.initializePageComponent), \'SP.Ribbon.js\');" +
"};" +
"COB.SharePoint.Ribbon.PageComponent.initializePageComponent = function() {" +
"var ribbonPageManager = SP.Ribbon.PageManager.get_instance();" +
"if (null !== ribbonPageManager) {" +
"ribbonPageManager.addPageComponent(COB.SharePoint.Ribbon.PageComponent.instance);" +
"}" +
"};" +
"COB.SharePoint.Ribbon.PageComponent.prototype = {" +
"init: function () { }," +
// some code there
"};" +
"function PopulateDropDown(commandId, properties, sequence){" +
"var sb = new Sys.StringBuilder();" +
"sb.append(\"<Menu Id=\'Sample.account.form.Menu\'>\");" +
"sb.append(\"<MenuSection Id=\'Sample.account.form.MenuSection\' Title=\'Menu Section Title\' Sequence=\'15\'>\");" +
"sb.append(\"<Controls Id=\'Sample.account.form.MenuSection.Controls\'>\");" +
"sb.append(\"<Button Id=\'Sample.account.form.Controls.Button.FirstButton\' Command=\'Sample.ButtonCommand.Command\' LabelText=\'First Button\' ToolTipTitle=\'First Button\' ToolTipDescription=\'The first button\' TemplateAlias=\'o2\' Sequence=\'20\' />\");" +
" sb.append(\"</Controls>\");" +
"sb.append(\"</MenuSection>\");" +
"sb.append(\"</Menu>\");" +
"CommandProperties.PopulationXML = sb.toString();return true;" +
"};" +
"COB.SharePoint.Ribbon.PageComponent.registerClass(\'COB.SharePoint.Ribbon.PageComponent\', CUI.Page.PageComponent);" +
"COB.SharePoint.Ribbon.PageComponent.instance = new COB.SharePoint.Ribbon.PageComponent();" +
"NotifyScriptLoadedAndExecuteWaitingJobs(\'COB.SharePoint.Ribbon.PageComponent.js\');";
populate.Update();
context.Load(site, oList => oList.UserCustomActions);
context.ExecuteQuery();
