I would like to add 2 custom actions to a SharePoint 2010 custom list. I'm adding the first custom action to the ribbon and it works perfectly. Then, I'm trying to add the second one using the same code but modifying just some attributes. It ending by having the 2 custom actions added but they are acting like they are the same. It just like I added 2 times the same custom action. Moreover, the one that should be enabled only when an item is selected is always enabled.
So my question is, is that possible to add 2 custom actions on the same list and how to do it?
Function AddUserCustomAction([Parameter(Mandatory=$True, Position=1)][hashTable]$parameters){
try{
$web = get-spweb $parameters.url;
$listTitle = $parameters.listTitle;
$list = $web.lists[$listTitle];
$userCustomActionsCollection = $list.userCustomActions;
$customAction = $parameters.userCustomActions
$customActiontitle = $customAction.title;
$newUserCustomAction = $userCustomActionsCollection.add();
$newUserCustomAction.CommandUIExtension = $customAction.CommandUIExtension;
$newUserCustomAction.Location = $customAction.Location;
$newUserCustomAction.Title = $customActionTitle;
$newUserCustomAction.Description = $customAction.Description;
$newUserCustomAction.Sequence = $customAction.Sequence;
$newUserCustomAction.Url = $customAction.Url;
$newUserCustomAction.update();
$list.update();
}catch{
$message = "Error : " + $Error[0].Exception.Message;
$message += "`r" + $Error[0].InvocationInfo.PositionMessage;
Log -message $message -color Red -date -filepath $LogFilePath;
}
}
$exportSelectedItemUCA = @{};
$exportSelectedItemUCA.RegistrationId = 101
$exportSelectedItemUCA.Title = 'sdfsdfsdf';
$exportSelectedItemUCA.Sequence = 2001;
$exportSelectedItemUCA.Location = 'CommandUI.Ribbon.ListView';
$exportSelectedItemUCA.Url = 'a/b/c.html';
$exportSelectedItemUCA.ScriptSrc = 'a/b/c.html';
$exportSelectedItemUCA.Id = 'Ribbon.Documents.New.RibbonCustomExcelExportPartial';
$exportSelectedItemUCA.Image32by32 = 'sdsdf/sdfsdsdfsd/sdfsdfsdf.png';
$exportSelectedItemUCA.Image16by16 = 'sdsdf/sdfsdsdfsd/sdfsdfsdf.16x16.png';
$exportSelectedItemUCA.Description = 'qsdqsdqsdqs';
$exportSelectedItemUCA.CommandAction = "javascript:exportSelectedItemsToExcelFile();"
$exportSelectedItemUCA.CommandUIExtension = '<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">' +
"<CommandUIDefinitions>" +
"<CommandUIDefinition "+
"Location=""Ribbon.List.Actions.Controls._children"">"+
"<Button Id="""+$exportSelectedItemUCA.Id+""" "+
"Alt="""+$exportSelectedItemUCA.Description+""" "+
"Command=""Notify"" "+
"Sequence="""+$exportSelectedItemUCA.Sequence+""" "+
"Image16by16="""+$exportSelectedItemUCA.Image16by16+""" "+
"Image32by32="""+$exportSelectedItemUCA.Image32by32+""" "+
"Description="""+$exportSelectedItemUCA.Description+""" "+
"LabelText="""+$exportSelectedItemUCA.Title+""" "+
"TemplateAlias=""o1""/>" +
"</CommandUIDefinition>"+
"</CommandUIDefinitions>"+
"<CommandUIHandlers>"+
"<CommandUIHandler "+
"Command=""Notify"" "+
"CommandAction="""+$exportSelectedItemUCA.CommandAction+""" "+
"EnabledScript=""javascript:SP.ListOperation.Selection.getSelectedItems().length == 1""/>"+
"</CommandUIHandlers>"+
"</CommandUIExtension>";
$parameters = @{
url = "/azeazeaz/azeazeaze";
listTitle = "qqsdqsdqsdqsd";
userCustomActions = $exportSelectedItemUCA
}
AddUserCustomAction $parameters;
$exportAllItemsUCA = @{};
$exportAllItemsUCA.RegistrationId = 102;
$exportAllItemsUCA.Title = 'eazeazeaze';
$exportAllItemsUCA.Sequence = 2002;
$exportAllItemsUCA.Location = 'CommandUI.Ribbon.ListView';
$exportAllItemsUCA.Url = 'a/b/c.html';
$exportAllItemsUCA.ScriptSrc = 'a/b/c.html';
$exportAllItemsUCA.Id = 'Ribbon.Documents.New.RibbonCustomExcelExportComplete';
$exportAllItemsUCA.Image32by32 = '/sdfsdf/sdfsdfsdf/sdfsdfsdf32x32.png';
$exportAllItemsUCA.Image16by16 = '/sdfsdf/sdfsdfsdf/sdfsdfsdf16x16.png';
$exportAllItemsUCA.Description = 'sdfsdfsdfsd.';
$exportAllItemsUCA.CommandAction = "javascript:getAllListsItems();"
$exportAllItemsUCA.CommandUIExtension = '<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">' +
"<CommandUIDefinitions>" +
"<CommandUIDefinition Location=""Ribbon.List.Actions.Controls._children"">"+
"<Button Id="""+$exportAllItemsUCA.Id+""" "+
"Alt="""+$exportAllItemsUCA.Description+""" "+
"Command=""Notify"" "+
"Sequence="""+$exportAllItemsUCA.Sequence+""" "+
"Image16by16="""+$exportAllItemsUCA.Image16by16+""" "+
"Image32by32="""+$exportAllItemsUCA.Image32by32+""" "+
"Description="""+$exportAllItemsUCA.Description+""" "+
"LabelText="""+$exportAllItemsUCA.Title+""" "+
"TemplateAlias=""o1""/>" +
"</CommandUIDefinition>"+
"</CommandUIDefinitions>"+
"<CommandUIHandlers>"+
"<CommandUIHandler "+
"Command=""Notify"" "+
"CommandAction="""+$exportAllItemsUCA.CommandAction+""" />"+
"</CommandUIHandlers>"+
"</CommandUIExtension>";
$parameters = @{
url = "/azeazeaz/azeazeaze";
listTitle = "qqsdqsdqsdqsd";
userCustomActions = $exportAllItemsUCA
}
AddUserCustomAction $parameters;
Note: I based my code on the one describe in those articles ( article 1 and article 2). I fixed the not working parts and it works nicely for a single custom action.
ScriptSrcas well asUrl. Try removing those properties and check if it works.ScriptSrcandUrl. Nothing changed.