/// <summary> /// Updates CRRelation view of related Graph with new ContactID if needed /// </summary> /// <param name="contact"></param> /// <param name="options"></param> protected virtual void FillDependedRelation(Contact contact, ContactConversionOptions options) { if (options?.GraphWithRelation != null) { var relation = (CRRelation)options.GraphWithRelation.Caches <CRRelation>()?.Current; var entity = Documents.Current; if (relation != null && relation.ContactID == null && relation.TargetNoteID == entity.NoteID) { relation.ContactID = contact.ContactID; options.GraphWithRelation.Caches <CRRelation>().RaiseFieldUpdated <CRRelation.contactID>(relation, null); options.GraphWithRelation.Caches <CRRelation>().MarkUpdated(relation); options.GraphWithRelation.Actions.PressSave(); } } }
public override ConversionResult <Contact> Convert(ContactConversionOptions options = null) { // do nothing if account already exist if (ExistingContact.SelectSingle() is Contact contact) { //PXTrace.WriteVerbose($"Using existing contact: {contact.ContactID}."); return(new ConversionResult <Contact> { Entity = contact, Converted = false, }); } var result = base.Convert(options); FillDependedRelation(result.Entity, options); return(result); }
protected override Contact CreateMaster(ContactMaint graph, ContactConversionOptions _) { var entity = Documents.Current; var param = ContactInfo.Current; var docContact = Contacts.Current ?? Contacts.SelectSingle(); var docContactMethod = ContactMethod.Current ?? ContactMethod.SelectSingle(); var docAddress = Addresses.Current ?? Addresses.SelectSingle(); Contact contact = new Contact { ContactType = ContactTypesAttribute.Person, ParentBAccountID = entity.ParentBAccountID }; MapContact(docContact, contact); MapConsentable(docContact, contact); contact.FirstName = param.FirstName; contact.LastName = param.LastName; contact.Salutation = param.Salutation; contact.Phone1 = param.Phone1; contact.Phone1Type = param.Phone1Type; contact.EMail = param.Email; contact.ContactType = ContactTypesAttribute.Person; contact.ParentBAccountID = entity.ParentBAccountID; contact.BAccountID = entity.BAccountID; contact.Source = entity.Source; MapContactMethod(docContactMethod, contact); var address = (Address)graph.AddressCurrent.Cache.CreateInstance(); address = graph.AddressCurrent.Insert(address); contact = graph.Contact.Insert(contact); contact.ClassID = param.ContactClass; CRContactClass cls = PXSelect < CRContactClass, Where < CRContactClass.classID, Equal <Required <CRContactClass.classID> > > > .SelectSingleBound(graph, null, contact.ClassID); if (cls?.DefaultOwner == CRDefaultOwnerAttribute.Source) { contact.WorkgroupID = entity.WorkgroupID; contact.OwnerID = entity.OwnerID; } MapAddress(docAddress, address); address = (Address)graph.AddressCurrent.Cache.Update(address); contact.DefAddressID = address.AddressID; contact = graph.Contact.Update(contact); ReverseDocumentUpdate(graph, contact); FillRelations(graph.Relations, contact); FillAttributes(graph.Answers, contact); TransferActivities(graph, contact); // Copy Note text and Files references CRSetup setup = PXSetupOptional <CRSetup> .Select(graph); PXNoteAttribute.CopyNoteAndFiles(graph.Caches <TMain>(), Documents.Cache.GetMain(entity), graph.Contact.Cache, contact, setup); return(graph.Contact.Update(contact)); }