You should be running for the specific scenario only.
Example: for products - check the tableId
if (this.RefTableId == tableNum(EcoResProdcut)
{
select firstonly RecId from docuRef
where docuRef.RefCompanyId== this.RefCompanyId &&
docuRef.Restriction == DocuRestriction::External &&
docuRef.RefTableId== this.RefTableId &&
docuRef.RefRecId == this.RefRecId;
if (docuRef.RecId)
{
info(strFmt(’%1’,docuRef.RefRecId));
throw error(“Already Exist”);
}
}