private static void ProcessValidation(ValidationFilter Filter, Contact record) { PXPrimaryGraphCollection primaryGraph = new PXPrimaryGraphCollection(new PXGraph()); PXGraph graph = primaryGraph[record]; if (graph == null) { throw new PXException(Messages.UnableToFindGraph); } PXView view = graph.Views[graph.PrimaryView]; int startRow = 0, totalRows = 0; List <object> list_contact = view.Select(null, null, new object[] { record.ContactID }, new string[] { typeof(Contact.contactID).Name }, null, null, ref startRow, 1, ref totalRows); if (list_contact == null || list_contact.Count < 1) { throw new PXException(Messages.ContactNotFound); } Contact contact = PXResult.Unwrap <Contact>(list_contact[0]); contact.DuplicateFound = true; //Find duplicates view PXView viewDuplicates = graph.Views.ToArray().First(v => v.Value.Cache.GetItemType() == typeof(CRDuplicateRecord)).Value; if (viewDuplicates == null) { throw new PXException(Messages.DuplicateViewNotFound); } viewDuplicates.Clear(); List <object> duplicates = viewDuplicates.SelectMulti(); contact = (Contact)view.Cache.CreateCopy(contact); string prevStatus = contact.DuplicateStatus; contact.DuplicateStatus = DuplicateStatusAttribute.Validated; Decimal?score = 0; contact.DuplicateFound = duplicates.Count > 0; foreach (PXResult <CRDuplicateRecord, Contact, Contact2> r in duplicates) { Contact2 duplicate = r; CRDuplicateRecord contactScore = r; int duplicateWeight = ContactMaint.GetContactWeight(duplicate); int currentWeight = ContactMaint.GetContactWeight(contact); if (duplicateWeight > currentWeight || (duplicateWeight == currentWeight && duplicate.ContactID < contact.ContactID)) { contact.DuplicateStatus = DuplicateStatusAttribute.PossibleDuplicated; if (contactScore.Score > score) { score = contactScore.Score; } } } view.Cache.Update(contact); if (contact.DuplicateStatus == DuplicateStatusAttribute.PossibleDuplicated && contact.ContactType == ContactTypesAttribute.Lead && contact.Status == LeadStatusesAttribute.New && Filter.CloseNoActivityLeads == true && score > Filter.CloseThreshold) { CRActivity activity = PXSelect <CRActivity, Where <CRActivity.contactID, Equal <Required <Contact.contactID> > > > .SelectWindowed(graph, 0, 1, contact.ContactID); if (activity == null) { PXAction action = graph.Actions["Action"]; PXAdapter adapter = new PXAdapter(view); adapter.StartRow = 0; adapter.MaximumRows = 1; adapter.Searches = new object[] { contact.ContactID }; adapter.Menu = Messages.CloseAsDuplicate; adapter.SortColumns = new[] { typeof(Contact.contactID).Name }; foreach (Contact c in action.Press(adapter)) { ; } prevStatus = null; } } view.Cache.RestoreCopy(record, view.Cache.Current); if (prevStatus != contact.DuplicateStatus) { graph.Actions.PressSave(); } }
public virtual IEnumerable CheckForDuplicates(PXAdapter adapter) { foreach (Contact rec in adapter.Get()) { Lead.Current = rec; Contact orig = rec; Contact lead = rec; if (lead.MajorStatus != LeadMajorStatusesAttribute._CLOSED && (adapter.ExternalCall || rec.DuplicateStatus == DuplicateStatusAttribute.NotValidated)) { lead = Lead.Cache.CreateCopy(Lead.Current) as Contact; lead.DuplicateStatus = DuplicateStatusAttribute.NotValidated; Lead.Update(lead); Lead.Current.DuplicateFound = true; Duplicates.View.Clear(); var result = Duplicates.Select(); Lead.Current.DuplicateFound = (result != null && result.Count > 0); lead = Lead.Cache.CreateCopy(Lead.Current) as Contact; lead.DuplicateStatus = DuplicateStatusAttribute.Validated; Decimal?score = 0; foreach (PXResult <CRDuplicateRecord, Contact, CRLeadContactValidationProcess.Contact2> r in result) { CRLeadContactValidationProcess.Contact2 duplicate = r; CRDuplicateRecord contactScore = r; int duplicateWeight = ContactMaint.GetContactWeight(duplicate); int currentWeight = ContactMaint.GetContactWeight(Lead.Current); if (duplicateWeight > currentWeight || (duplicateWeight == currentWeight && duplicate.ContactID < Lead.Current.ContactID)) { lead.DuplicateStatus = DuplicateStatusAttribute.PossibleDuplicated; if (contactScore.Score > score) { score = contactScore.Score; } } } if (orig.DuplicateStatus != lead.DuplicateStatus) { lead = Lead.Update(lead); } if (Lead.Current.DuplicateFound == false && adapter.ExternalCall) { Lead.Cache.RaiseExceptionHandling <Contact.duplicateStatus>(lead, null, new PXSetPropertyException( Messages.NoPossibleDuplicates, PXErrorLevel.RowInfo)); } } yield return(lead); } if (Lead.Cache.IsDirty) { Save.Press(); } }
private static void ProcessValidation(ValidationFilter filter, Contact record) { BusinessAccountMaint graph = PXGraph.CreateInstance <BusinessAccountMaint>(); PXView view = graph.BAccount.View; int startRow = 0, totalRows = 0; BAccount baccount = null; Contact contact = null; if (record.ContactType == ContactTypesAttribute.BAccountProperty && record.BAccountID != null) { List <object> list_baccount = view.Select(null, null, new object[] { record.BAccountID }, new string[] { typeof(BAccount.bAccountID).Name }, null, null, ref startRow, 1, ref totalRows); if (list_baccount != null && list_baccount.Count >= 1) { baccount = PXResult.Unwrap <BAccount>(list_baccount[0]); } } if (baccount == null || baccount.DefContactID != record.ContactID) { throw new PXException(Messages.ContactNotFound); } contact = graph.DefContact.Current = graph.DefContact.SelectWindowed(0, 1); contact.DuplicateFound = true; PXView viewDuplicates = graph.Duplicates.View; if (viewDuplicates == null) { throw new PXException(Messages.DuplicateViewNotFound); } viewDuplicates.Clear(); List <object> duplicates = viewDuplicates.SelectMulti(); contact = (Contact)graph.DefContact.Cache.CreateCopy(contact); contact.DuplicateStatus = DuplicateStatusAttribute.Validated; Decimal?score = 0; foreach (PXResult <CRDuplicateRecord, Contact, CRLeadContactValidationProcess.Contact2> r in duplicates) { CRLeadContactValidationProcess.Contact2 duplicate = r; CRDuplicateRecord contactScore = r; int duplicateWeight = ContactMaint.GetContactWeight(duplicate); int currentWeight = ContactMaint.GetContactWeight(contact); if (duplicateWeight > currentWeight || (duplicateWeight == currentWeight && duplicate.ContactID < contact.ContactID)) { contact.DuplicateStatus = DuplicateStatusAttribute.PossibleDuplicated; if (contactScore.Score > score) { score = contactScore.Score; } } } graph.DefContact.Cache.Update(contact); graph.DefContact.Cache.RestoreCopy(record, contact); graph.Actions.PressSave(); }