Assigning a File to an Item


In Vault 2015, PromoteFiles has been removed from the ItemService.  Previously, the quickest way was to call PromoteFiles followed by UpdateAndCommitItems.  Of course, more complex cases would require more API calls and data checks.  Anyway, the simple workflow just got more complex in 2015.  That’s sometimes the price you pay for better functionality.

Before I dive into the new code, let me explain the reason for the change.  First, PromoteFiles was not very efficient.  It tried to do the entire BOM at once, which is bad for server performance and scalability.  Next, it favored a file-first workflow (the files need to get created before the items).  In Vault 2015, there is much better support for item-first workflows, which I’ll go over in other articles.

For now, let’s go back to the simple file-first case.  You have an Inventor assembly checked-in and you want to create the BOM in Vault.


Here is the code for doing that…

// C#

 

ItemService itemSvc = m_conn.WebServiceManager.ItemService;

itemSvc.AddFilesToPromote(fileIds, ItemAssignAll.Default, false);

 

DateTime timestamp;

GetPromoteOrderResults promoteOrder =

    itemSvc.GetPromoteComponentOrder(out timestamp);

itemSvc.PromoteComponents(timestamp, promoteOrder.PrimaryArray);

ItemsAndFiles itemsAndFiles =

    itemSvc.GetPromoteComponentsResults(timestamp);

 

// TODO: edit the items if needed

 

itemSvc.UpdateAndCommitItems(itemsAndFiles.ItemRevArray);

' VB.NET

 

Dim itemSvc AsItemService = m_conn.WebServiceManager.ItemService

itemSvc.AddFilesToPromote(fileIds, 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)

Basically, PromoteFiles has been replaced by 4 function calls: AddFilesToPromote, GetPromoteComponentOrder, PromoteComponents, and GetPromoteComponentsResults.  The "timestamp" variable is the thread that ties together the four calls.  When you want to finalize the operation, call UpdateAndCommitItems just like before.

Yes, it seems like 4 function calls makes things worse than before.  It's definitely more work for a client, but it makes and improvement on the server side.  Less is done in a single call, which means that transactions are smaller and quicker.  That, in turn, means more concurrency and throughput.

Click here for an article on how to update an Item in response to File updates



Comments

8 responses to “Assigning a File to an Item”

  1. Hi Doug,
    first of all many thanks for this article.
    I need some help to update a Vault Extension from 2013 to 2015. I made an extension that automatically update an item to the most recent file version during the checkout_Post event of Inventor. This extension uses the old-and-removed function “UpdateFromFile”.
    With the new Vault SDK i’m not able to obtain the same result; i don’t want to made a new item revision every time due to my company restrictions.
    I’ve tried the new “UpdateItemFileAssociation” passing the unique Id coming from the Inventor CheckIn event, but in Vault the result is that the item lose his file (the primary). If i manually do an Update from the Vault client all is ok again….but the intention of this extension is exactly to do an automatic item update.
    I’m quite desperate….
    Thanks anyway in advance
    Dave

  2. I should probably write a blog article with a sample of the Update workflow.
    In the meantime try this:
    Use the code from this article but replace the “AddFilesToPromote” call with a call to “UpdatePromoteComponents”. The rest of the sample should be the same.

  3. Hi Doug,
    Thanks so much for all your insights.
    I have used your code to build an app for promoting all legacy files to Items. The problem is, this code works perfect on single part files (.ipt), but assemblies (.iam) with components throw an error code (1387) for restrictions. I used your code, to drill down in the exception, and found the following exception, (2037) Operation cannot be performed because the item is not in an editable state. Can you please help?

  4. Is the error thrown on UpdateAndCommitItems?
    If so, I suggest looking at the “status” array on the itemsAndFiles object. If the status on an Item is 1 (unaffected), then the Item wasn’t edited. When calling UpdateAndCommitItems, only pass in the Items that were promoted or updated.

  5. Never mind, I found the solution in one of your older blog posts. The issue was that GetPromoteComponentsResults() was returning more Items that I needed, and some of them were not in edit mode.

  6. Yes, I saw that. Thank you for the fast reply.

  7. Vismantas Avatar
    Vismantas

    Hello Doug,
    I use your code to create BOM for assembly and I need all BOM rows to be enabled. I call AddFilesToPromote(ids, ItemAssignAll.Yes, false) method. Created BOM seems OK but only one child row of the top assembly is enabled in created BOM. Why other rows are not enabled? The following BOM lines are created.
    TopAssembly
    |_SubAssembly(turned on)
    | |_PartOfSubAssembly(turned off)
    |_PartOfTopAssembly(turned off)
    Can you please help me?

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading