Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HelloWorld for Items

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
tommam
781 Views, 4 Replies

HelloWorld for Items

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

4 REPLIES 4
Message 2 of 5
Redmond.D
in reply to: tommam

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.

 



Doug Redmond
Software Engineer
Autodesk, Inc.

Message 3 of 5
John204
in reply to: Redmond.D

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.

Message 4 of 5
psaarloos
in reply to: John204

Hi,

 

Try this:

 

Dim item as Item = _connection.WebServiceManager.ItemService.GetItemsByIds(new long() { selection.Id }).FirstOrDefault()

Hope it helps.

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
Message 5 of 5
John204
in reply to: psaarloos

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!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report