By Wayne Brill
You can use GetItemBOMByItemIdAndDate() to get the "where used" information from an Item. Using "Tip" for BOMtyp and "Defaults" for the BOMViewEditOptions will allow you to get both the parents and children of the Item.
Here is a C# example:
static void GetWhereUsed()
{
// Set up the login credentials for Vault.
// For demonstration purposes, the
// information is hard-coded.
UserPasswordCredentials login =
new UserPasswordCredentials(
"localhost", "Vault", "Administrator",
"",
false
);
using (WebServiceManager serviceManager =
new WebServiceManager(login))
{
try
{
PropDef[] props =
serviceManager.PropertyService.
FindPropertyDefinitionsBySystemNames
("ITEM", new string[] { "Number" });
//Find items that you are interested in.
if (props != null)
{
SrchCond srchConds = new SrchCond();
srchConds.PropDefId =
Convert.ToInt64(props[0].Id);
srchConds.PropTyp =
PropertySearchType.SingleProperty;
srchConds.SrchRule = SearchRuleType.Must;
// (CONTAINS)
srchConds.SrchOper =
Convert.ToInt32(1);
// (DOES_NOT_CONTAIN)
//srchConds.SrchOper =
// Convert.ToInt32(2);
// Number of the Item
srchConds.SrchTxt = "100005";
string bookmark = String.Empty;
SrchStatus searchStatus = null;
SrchSort ss = new SrchSort()
{
PropDefId = srchConds.PropDefId,
SortAsc = true
};
//Get the items
Item[] myItems =
serviceManager.ItemService
.FindItemRevisionsBySearchConditions
(new SrchCond[] { srchConds },
new SrchSort[] { ss },
true,
ref bookmark,
out searchStatus);
//Get the first item
Item myItem = myItems[0];
// Get parents and children for the Item
if (myItem != null)
{
ItemBOM bom =
serviceManager.ItemService.
GetItemBOMByItemIdAndDate
(myItem.Id,
System.DateTime.Today,
BOMTyp.Tip,
BOMViewEditOptions.Defaults);
Item[] ItemRevArray = bom.ItemRevArray;
ItemAssoc[] ItemAssocArray =
bom.ItemAssocArray;
ItemBOMOcc[] OccurArray =
bom.OccurArray;
//ItemAssocArray contains the association
//information between any two items in
//ItemRevArray.
//ItemRevArray contains all items that
//you see from "where used" tab.
// Do something here...
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}//using
}
