By Wayne Brill
In Vault Explorer you can use the Update command to make the version of an associated file the latest version.
This C# example shows how this update is done through the API using ItemService.PromoteComponents().
You can test this code by adding a button to this SDK sample:
“C:Program Files (x86)AutodeskAutodesk Vault 2014 SDKVS10CSharpItemEditor”
private void button2_Click(object sender, EventArgs e) { if (m_selectedItem == null) { MessageBox.Show("Select an Item first"); return; } long[] itemRevisionIds = new long[1]; itemRevisionIds[0] = m_selectedItem.RevId; Item[] itemsToCommit = new Item[0]; long[] itemsToCommit_Ids = new long[0]; try { ItemService itemSvc = m_connection.WebServiceManager.ItemService; itemSvc.UpdatePromoteComponents(itemRevisionIds); DateTime now = DateTime.Now; long[] compO = itemSvc.GetPromoteComponentOrder(out now); ArrayList compOrder = new ArrayList(compO); ArrayList subSet = new ArrayList(); int setSize = 100; int setNum = 0; //get full sets while (setNum < compOrder.Count / setSize) { subSet = compOrder.GetRange (setNum * setSize, setSize); itemSvc.PromoteComponents (now, (long[])subSet.ToArray(typeof(long))); setNum++; } //get remaining set if (compOrder.Count % setSize > 0) { subSet = compOrder.GetRange (setNum * setSize, compOrder.Count % setSize); itemSvc.PromoteComponents (now, (long[])subSet.ToArray(typeof(long))); } ItemsAndFiles result = itemSvc. GetPromoteComponentsResults(now); Item[] items = null; items = result.ItemRevArray; int[] statusArray = result.StatusArray; // loop through the Items in the ItemRevArray for (int i = 0; i < items.Length; i++) { // see if the item in the ItemRevArray //has been upd
ated (not equal to 1) if (statusArray[i] != 1) { //change the size of the array Array.Resize(ref itemsToCommit, itemsToCommit.Length + 1); //add the updated item to the array //that will be committed itemsToCommit[itemsToCommit.Length - 1] = items[i]; } } //commit the updated items itemSvc.UpdateAndCommitItems(itemsToCommit); // Testing catch - this could cause error // as items contains Items that may // not need to be updated // itemSvc.UpdateAndCommitItems(items); } catch { // get the items that need to be undone for (int i = 0; i < itemsToCommit.Length; i++) { // change the size of the array // of Ids (long) Array.Resize(ref itemsToCommit_Ids, itemsToCommit_Ids.Length + 1); //Add the id to the array that will be // used in UndoEditItems() itemsToCommit_Ids [itemsToCommit_Ids.Length - 1] = itemsToCommit[i].Id; } m_connection.WebServiceManager.ItemService. UndoEditItems(itemsToCommit_Ids); } }


Leave a Reply