Autodesk Vault ProfessionalVault API

ReassignComponentsToDifferentItems Method

Autodesk.Connectivity.WebServicesItemService

Assigns a Component to a different Item.

Required Permissions

FileUpdate

Syntax

public Item[] ReassignComponentsToDifferentItems(
   System.long[] sourceItemIds,
   System.long[] destIds
)
Public Function ReassignComponentsToDifferentItems( _
   ByVal sourceItemIds() As System.Long, _
   ByVal destIds() As System.Long _
) As Item()

Parameters

NameDescription
sourceItemIdsA list of new Items which have not yet been committed.
destIdsA list of destination Items. Items do not need to be locked for editing.

Return Value

An array of new destination Items. The Items are editable. Call a commit function, such as UpdateAndCommitItems to finalize the changes.

Example

using Autodesk.Connectivity.WebServices;
using Autodesk.Connectivity.WebServicesTools;

class VaultSDKSample
{
    public void AssignFileToItem(WebServiceManager serviceManager, Item selectedItem, File selectedFile)
    {
        ItemsAndFiles promoteResult = null;
        Item[] updatedItems = null;
        try
        {
            // first assign the file to a new item
            // this example assumes that only 1 item will result from the promote
            promoteResult = serviceManager.ItemService.PromoteFiles(new long[] { selectedFile.Id });

            // next reassign the file from the new item to the existing item
            updatedItems = serviceManager.ItemService.ReassignComponentsToDifferentItems(
            new long[] { promoteResult.ItemRevArray[0].Id },
            new long[] { selectedItem.Id });

            // commit the changes
            serviceManager.ItemService.UpdateAndCommitItems(updatedItems);
        }
        catch
        {
            if (updatedItems != null && updatedItems.Length > 0)
            {
                long[] itemIds = new long[updatedItems.Length];
                for (int i = 0; i < updatedItems.Length; i++)
                {
                    itemIds[i] = updatedItems[i].Id;
                }
                serviceManager.ItemService.UndoEditItems(itemIds);
            }
        }
        finally
        {
            if (promoteResult != null)
            {
                // clear out the promoted item
                serviceManager.ItemService.DeleteUnusedItemNumbers(new long[] { promoteResult.ItemRevArray[0].MasterId });
                serviceManager.ItemService.UndoEditItems(new long[] { promoteResult.ItemRevArray[0].Id });
            }
        }
    }
}
Imports Autodesk.Connectivity.WebServices

Class VaultSDKSample
    Public Sub AssignFileToItem(serviceManager As Autodesk.Connectivity.WebServicesTools.WebServiceManager, selectedItem As Item, selectedFile As File)
        Dim promoteResult As ItemsAndFiles = Nothing
        Dim updatedItems As Item() = Nothing
        Try
            ' first assign the file to a new item
            ' this example assumes that only 1 item will result from the promote
            promoteResult = serviceManager.ItemService.PromoteFiles(New Long() {selectedFile.Id})

            ' next reassign the file from the new item to the existing item
            updatedItems = serviceManager.ItemService.ReassignComponentsToDifferentItems( _
                New Long() {promoteResult.ItemRevArray(0).Id}, New Long() {selectedItem.Id})

            ' commit the changes
            serviceManager.ItemService.UpdateAndCommitItems(updatedItems)
        Catch
            If updatedItems IsNot Nothing AndAlso updatedItems.Length > 0 Then
                Dim itemIds As Long() = New Long(updatedItems.Length - 1) {}
                For i As Integer = 0 To updatedItems.Length - 1
                    itemIds(i) = updatedItems(i).Id
                Next
                serviceManager.ItemService.UndoEditItems(itemIds)
            End If
        Finally
            If promoteResult IsNot Nothing Then
                ' clear out the promoted item
                serviceManager.ItemService.DeleteUnusedItemNumbers(New Long() _
                    {promoteResult.ItemRevArray(0).MasterId})
                serviceManager.ItemService.UndoEditItems(New Long() {promoteResult.ItemRevArray(0).Id})
            End If
        End Try
    End Sub
End Class

See Also