Use UpdateAndCommitItem()to change the Category of an Item

By Wayne Brill

The function to change the category of an item may not be easy to find. To change the category of a file you can use  UpdateFileCategories(). To change the category of a folder you use UpdateFolderCategories(). To change the category of an Item you change the ItemTypId field of the item and then use UpdateAndCommitItem().

You can test this using the code below by adding a button to the ItemEditor example.

C:Program Files (x86)AutodeskAutodesk Vault 2014 SDKVS10VBItemEditor

 

Private Sub Button1_Click _    (sender As System.Object, e As System.EventArgs) _                     Handles Button1.Click             Dim myItem As Item = Nothing             Try            ' Using this to get the category to change            ' the Item to. On the form select the             ' dropdown for the Type (category).             ' Not using the Title so just leave            ' it blank and hit ok            Dim form As New CreateItemForm(m_connection)            form.ShowDialog()                 If form.DialogResult  DialogResult.OK Then                Return            End If            ' Get the latest item            Dim itemRev As Item =                m_connection.WebServiceManager.ItemService. _            GetLatestItemByItemNumber(m_selectedItem.ItemNum)            'Edit the item            myItem = m_connection.WebServiceManager. _                         ItemService.EditItem(itemRev.RevId)            'Change the category of the item            myItem.ItemTypId = form.Category.Id '3            'commit            m_connection.WebServiceManager.ItemService. _                UpdateAndCommitItem(myItem, _                   0, False, Nothing, Nothing, _                   Nothing, Nothing, Nothing, _                   Nothing, 2)             Catch ex As Exception            If Not myItem Is Nothing Then                m_connection.WebServiceManager. _    ItemService.UndoEditItems(New Long() {myItem.Id})            End If                 MessageBox.Show _                ("Error occurred " + ex.ToString())             End Try    End Sub

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading