Prevent duplicate vendor records

I am currently facing a problem managing my vendors in Epicor. Several of them have been registered two or more times, so I am looking for a way to prevent this situation.

The idea is for a vendor to be unique, considering the fields Company, TaxPayerID, and CurrencyCode

Create a BPM (Business Process Management) as follows:

the custom code is:

bool vExist = false;
foreach (var ttVendor_Recs in (from ttVendor_Row in ttVendor where ttVendor_Row.RowMod == IceRow.ROWSTATE_ADDED
select ttVendor_Row))
{
    var ttVendorRow = ttVendor_Recs;
    if (ttVendor_Recs != null)
    {
        var Vendor_Recs = (from Vendor_Row in Db.Vendor 
        where Vendor_Row.Company == Session.CompanyID && Vendor_Row.TaxPayerID == vTaxPayerID && Vendor_Row.CurrencyCode == vCurrencyCode
        select Vendor_Row).FirstOrDefault();
        if (Vendor_Recs == null)
        {
           // Epicor.Customization.Bpm.InfoMessage.Publish("No Records");
            vExist = false;
        }
        else
        {
            vExist = true;
        }
    }
}

The exception should be triggered, but it is firing when a record is added, updated, or deleted.

How can I prevent this and ensure that my records are not duplicated?

Am I on the right track to execute this BPM, or am I completely wrong in what I’m doing?

Your local variable called vexists isn’t going to be available outside to check

You need to use the scoped variable

1 Like

Thank you!, It is already working correctly

The BPM works when a new supplier is added, but it also triggers when a Contact, GL Control, Bank, or any record involving an update method is added.

How can I detect that the BPM is activated only when saving the data from the Supplier Detail tab?

image

It will always trigger when saving. However, it won’t do anything unless there is an added row to ttVendor.

1 Like