Hi @terpstra,
I believe, You can accomplish the desired behavior through customization.
By adding logic in the RowPersisting event, you can retrieve the vendor information from the Vendors tab using a BQL query. If no vendor is found, you can set an exception to prevent the item from being saved.
You can use the code provided below to achieve this functionality.
public class InventoryItemMaint_Extension : PXGraphExtension<InventoryItemMaint>
{
protected void InventoryItem_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (InventoryItem)e.Row;
if (row == null) return;
// Check if at least one vendor is entered in the Vendor tab
int? inventoryID = row.InventoryID;
if (inventoryID != null)
{
POVendorInventory vendor = PXSelect<POVendorInventory,
Where<POVendorInventory.inventoryID, Equal<Required<POVendorInventory.inventoryID>>>>
.Select(Base, inventoryID);
// If no vendor is found, throw an error
if (vendor == null)
{
cache.RaiseExceptionHandling<InventoryItem.inventoryCD>(row,
row.InventoryCD, new PXSetPropertyException("At least one vendor must be entered in the Vendor tab.", PXErrorLevel.Error));
// Prevent the record from being saved
throw new PXRowPersistingException(typeof(InventoryItem.inventoryCD).Name, row.InventoryCD, "At least one vendor is required.");
}
}
}
}