carstenw
9 years agoCreator II
How to get items on the BOM before save
Hi,
the use case is as follows: A user adds items to a BOM, some of which have a (custom made) state of Obsolete
I would like to get all the items on the BOM before the Part is saved, filter out the Obsolete and present their item_number in an error message to the user to instruct him to replace those.
How do I go about that? I have tried a bit of XPath, of which I am a complete novice, but only managed to get back the items already saved on the BOM.
The following is of course flawed, since the only items i can get from the
this object are the ones already saved
Any suggestions welcome :)
item = this;
var relitemsList = item.getItemsByXPath("Relationships/Item[@type='Part BOM']");
var relCount = relitemsList.getItemCount();
for (int i = 0; i < relCount; i++)
{
var relItem = relitemsList.getItemByIndex(i);
var bomItem = relItem.getRelatedItem();
var relatedState = bomItem.getProperty("eht_production_lc_state");
var relatedNumber = bomItem.getProperty("item_number");
if (relatedState == "Obsolete")
{
affectedParts += relatedNumber + "\r\n";
}
}
if (string.IsNullOrEmpty(affectedParts)) return item;
var errorMsg = "Cannot save item because the following items on the BOM are obsolete:\r\n" + affectedParts;
return inn.newError(errorMsg);