Updating an Item from File

A while back I posted some code showing how to create Items from Files.  This time I’ll post code code showing how to update those Items when you want to consume File changes. 

The code is almost identical.  The creating Items from Files and updating Items from Files are actually the same operation under the hood.  The only difference is how the process gets kicked off.  When creating Items, you start with a set of Files.  When updating Items, you start with a set of Items.

Here is the code for the update operation.  This time around UpdatePromoteComponents kicks off the process.  Again, this is a very simplified example.  More complex BOMs may involve more code.


// C#

 

ItemService itemSvc = m_conn.WebServiceManager.ItemService;

itemSvc.UpdatePromoteComponents(itemRevIds,
    ItemAssignAll.Default, false);

DateTime timestamp;

GetPromoteOrderResults promoteOrder =

    itemSvc.GetPromoteComponentOrder(out timestamp);

itemSvc.PromoteComponents(timestamp, promoteOrder.PrimaryArray);

ItemsAndFiles itemsAndFiles =
    itemSvc.GetPromoteComponentsResults(timestamp);

 

// edit the items as needed

 

itemSvc.UpdateAndCommitItems(itemsAndFiles.ItemRevArray);


'
VB.NET

Dim itemSvc AsItemService = m_conn.WebServiceManager.ItemService

itemSvc.UpdatePromoteComponents(itemRevIds, _
    ItemAssignAll.Default,
False)

Dim timestamp AsDateTime

Dim promoteOrder As GetPromoteOrderResults = _
    itemSvc.GetPromoteComponentOrder(timestamp)

itemSvc.PromoteComponents(timestamp, promoteOrder.PrimaryArray)

Dim itemsAndFiles AsItemsAndFiles = _

    itemSvc.GetPromoteComponentsResults(timestamp)

 

' edit the items as needed

 

itemSvc.UpdateAndCommitItems(itemsAndFiles.ItemRevArray)



Comments

4 responses to “Updating an Item from File”

  1. Pim Saarloos Avatar
    Pim Saarloos

    Hi Doug,
    I am trying to update an item according to this sample, but with one difference. I need to have the ‘autoAssignDuplicates’ property in the UpdatePromoteComponents method set to ‘true’.
    How does the ‘autoAssignDuplicates’ work?
    We used to have a function ‘GetItemDuplicateCandidates’, which is removed in Vault 2015, to get to know the possible duplicates. I used this function together with the ‘ReassignComponentsToDifferentItems’ function to assign the duplicates to the proper item. What can I use in Vault 2015 to get to know more information about the duplicates?
    Regards,
    Pim Saarloos

  2. Here is the answer I got back from the Vault team…
    Since Vault no longer has a wizard, the assign-duplicate functionality is automated.
    In the new code, auto assign duplicates = true will attempt to find duplicate items for all bom components and will link them if possible. If a match is found, the component will be linked to the first candidate. There is no user/API interaction involved in this decision.
    Vault 2015 also auto links all subcomponents and standard components regardless of the flag. This behavior has been identified as a bug and may be changed in the near future.

  3. Hi Doug,
    i have a hybrid scenario that i cannot solve.
    In Vault 2015 i have an item without any primary file – an “empty box” created from another external procedure.
    The drafter, in Inventor, do the draft and simply Add file in Vault. My extension must link the ipt/iam with the correct item. Here’s the problem: your code below does not work in this case. All can i do is AssignFileToItem first, and then UpdateAndCommitItems. In Vault i finally have the File linked with the correct Item, but i don’t have the Item preview updated!! To be “all-fine” i must manually go inside the Vault GUI, catch the Item and do the update manually.
    Is there a way to do it? In Vault 2013 i made this with the “classic” PromoteFiles – probably with less performance but certainly more powerful as use
    Regards,
    Dave

  4. Erik Gilsdorf Avatar
    Erik Gilsdorf

    In a perfect developer’s world, where there is only one duplicate candidate, this might work…
    In real world there is a 1/n chance to get the right candidate.

Leave a Reply