Is it possible to require the user to enter a vendor to create a stock item?
When creating new stock items, we want the vendor tab to have at least one vendor entered to allow the item to be saved.
I do not see a way that this would be possible without creating a customization to the system.
Page 1 / 1
I have used this simple video to make fields mandatory. Hopefully it works for your situation as well
I have used this simple video to make fields mandatory. Hopefully it works for your situation as well
I tried that, but it only seemed to apply when creating a record in the Vendors tab.
I did not see an option to require at least one record to exist. I am not a customization expert though, so I could definitely be missing something.
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."); } } } }
@Dipak Nilkanth
Not super familiar with custom code projects.
Where would I publish that code?
Would I create a code file in the customization project?
If so, what file template type would I use?
Thanks in advance!
Hi @terpstra,
Select File Template as Graph Extension. and select Base Graph as PX.Objects.IN.InventoryItemMaint.