Skip to main content
Solved

Require Vendor for Stock Item Creation

  • 6 September 2024
  • 5 replies
  • 52 views

Hello,

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.

Best answer by Nilkanth Dipak

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.");
            }
        }
    }
}

 

View original
Did this topic help you find an answer to your question?

5 replies

Forum|alt.badge.img
  • Jr Varsity II
  • 23 replies
  • September 6, 2024

I have used this simple video to make fields mandatory. Hopefully it works for your situation as well

 

https://www.youtube.com/watch?v=LSC8y3AONoE

 


  • Author
  • Freshman II
  • 8 replies
  • September 6, 2024
afranklin wrote:

I have used this simple video to make fields mandatory. Hopefully it works for your situation as well

 

https://www.youtube.com/watch?v=LSC8y3AONoE

 

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.


Nilkanth Dipak
Varsity I
Forum|alt.badge.img+8
  • Varsity I
  • 316 replies
  • Answer
  • September 7, 2024

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.");
            }
        }
    }
}

 


  • Author
  • Freshman II
  • 8 replies
  • September 16, 2024

@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!


Nilkanth Dipak
Varsity I
Forum|alt.badge.img+8

Hi @terpstra,

Select File Template as Graph Extension. and select Base Graph as PX.Objects.IN.InventoryItemMaint.

Extend graph

please let me know if it helps you.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings