How to automatically handle item iterationNumbers in the bcpToolkit .NET library
Issue
When creating a bcp package using the bcpToolkit .NET library the iterationNumber is currently resetting for each revision. If not handled in the code this can cause a violation of unique key constraint (Exception: ImportItemDataFromXMLFailed [1450]) in the DTU when importing the package into Vault because the iterationNumber has to be unique inside an itemMaster.
Solution
For a guide on how to get started with the bcpToolkit .NET library please refer to the Getting Started section on the coolOrange wiki.
Add an Item
After you have created the Visual Studio project and followed the required steps, add an item to the package passing the required parameters. The item gets added with its first iteration.
var itemMaster = bcpService.ItemService.AddItem("ItemNumber", "category", "title", "desc");
Now another revision can be added which creates a new iteration of the item.
var itemRevision = itemMaster.AddRevision("rev1", "rev1desc");
Automatically handle item iterations
Now with 2 item revisions you can add following line of code to get the highest iteration number of the item and add +1 to the latest iteration
itemRevision.Iterations.Last().IterationNumber = itemMaster.Revisions.SelectMany(rev => rev.Iterations).Max(iter => iter.IterationNumber) + 1;