按触发器跳过记录是不正确的,因为您的文档总数会错误。
如果您可以使用触发器来处理它,那么如果系统会自动跳过此项目而没有任何消息,我认为您可以吗?
如果是,此自定义可能对您有用。它将检查数据库中的类似记录并将其删除。如果有不同的要求,您可以更改此代码并抛出错误或选择不同的选择。
请注意,这取决于数据的大小,它可能会影响性能。我强烈建议您在列上创建自定义索引。
public class ARInvoiceEntry_Extension : PXGraphExtension<ARInvoiceEntry>
{
public delegate void PersistDelegate();
[PXOverride]
public void Persist(PersistDelegate baseMethod)
{
if (Base.IsImport)
{
PXView _view = new PXView(Base, false, BqlCommand.CreateInstance(typeof(Select<ARTran, Where<ARTranExt.usrCustomKey, Equal<Required<ARTranExt.usrCustomKey>>>>)));
//Checking Unique Value
foreach (ARTran tran in Base.Transactions.Select())
{
ARTranExt ext = Base.Transactions.Cache.GetExtension<ARTranExt>(tran);
String search = ext.UsrCustomKey;
if (search != null)
{
int startRow = 0, maxRows = 2, totalRows = 0;
List<object> records = _view.Select(null, new[] { search }, null, null, null, null, ref startRow, maxRows, ref totalRows);
bool found = false;
foreach (ARTran record in records)
{
if (found) // if it's not the same record
{
Base.Transactions.Delete(record);
}
found = true;
}
}
}
}
baseMethod();
}
}