I'm trying to take the HelloWorld sample code and get it to work for items instead of files. I've changed the navigation types in the CommandSites function:
NavigationTypes = new SelectionTypeId[] { SelectionTypeId.Item },
and I've redefined the HelloWorldCommandHandler:
void HelloWorldCommandHandler(object s, CommandItemEventArgs e)
{
try
{
// The Context part of the event args tells us information about what is selected.
// Run some checks to make sure that the selection is valid.
if (e.Context.CurrentSelectionSet.Count() == 0)
MessageBox.Show("Nothing is selected");
elseif (e.Context.CurrentSelectionSet.Count() > 1)
MessageBox.Show("This function does not support multiple selections");
else
{
// we only have one item selected, which is the expected behavior
ISelection selection = e.Context.CurrentSelectionSet.First();
// Look of the Item object. How we do this depends on what is selected.
Item selectedItem = null;
if (selection.TypeId == SelectionTypeId.Item)
{
selectedItem = m_mgr.ItemService.GetLatestItemByItemMasterId(selection.Id);
}
...
Now when I run it, I am able to go to the Item Master, right click on an item that is at Work In Progress and select my custom command. If I then step through the command handler, it goes good until I get to the last line above, where I call "GetLatestItemByItemMasterId". It throws error 1200.
Any idea what I'm doing wrong? (We're running Vault Pro 2013.)
Thanks,
Tom
Solved! Go to Solution.
Solved by Redmond.D. Go to Solution.
Selection.Id has different meanings depending on the selection type. If type is "Item" then the selection ID is the Item.Id value, which is different than Item.MasterId. GetItemsByIds is the function you want to call for the last line.
Hi,
I gave this a try in Vault 2016 but when I use GetItemsByIds and pass in selection.Id, I get an error in Visual Studio stating "Value of type 'Long' cannot be converted to 'Long()'. I'm eventually trying to read the item category of the selected item but seem to be stuck getting at the current item.
Thanks.
Hi Pim,
After posting my question, I checked the SDK documentation and realized that GetItemsByIds wants an array passed in. Your solution works great, thanks!