protected PXFieldState InitValueFieldState(FieldValue field) { Tuple <IEnumerable <string>, IEnumerable <string> > possibleValues = new Tuple <IEnumerable <string>, IEnumerable <string> >(new string[0], new string[0]); List <TMain> entities = new List <TMain>(PXSelectorAttribute.SelectAll <MergeParams.targetEntityID>(Base.Caches[typeof(MergeParams)], Base.Caches[typeof(MergeParams)].Current).RowCast <TMain>()); if (field.CacheName == typeof(TMain).FullName) { possibleValues = GetPossibleValues(Base, entities, field.Name); } else if (field.CacheName == typeof(Contact).FullName && field.CacheName != typeof(TMain).FullName) { PXSelectBase <Contact> cmd = new PXSelect <Contact>(Base); List <int?> defContactIDs = new List <int?>(entities.Select(entity => Base.Caches[typeof(TMain)].GetValue(entity, nameof(Document.DefContactID)) as int?).Where(c => c != null)); foreach (int?c in defContactIDs) { cmd.WhereOr <Where <Contact.contactID, Equal <Required <BAccount.defContactID> > > >(); } possibleValues = GetPossibleValues(Base, cmd.Select(defContactIDs.Cast <object>().ToArray()).RowCast <Contact>(), field.Name); } else if (field.CacheName == typeof(Address).FullName) { PXSelectBase <Address> cmd = new PXSelect <Address>(Base); List <int?> addressIDs = new List <int?>(entities.Select(entity => Base.Caches[typeof(TMain)].GetValue(entity, nameof(Document.DefAddressID)) as int?).Where(c => c != null)); foreach (int?a in addressIDs) { cmd.WhereOr <Where <Address.addressID, Equal <Required <Address.addressID> > > >(); } possibleValues = GetPossibleValues(Base, cmd.Select(addressIDs.Cast <object>().ToArray()).RowCast <Address>(), field.Name); } string[] values = possibleValues.Item1.ToArray(); string[] labels = possibleValues.Item2.ToArray(); return(PXStringState.CreateInstance(field.Value, null, null, typeof(FieldValue.value).Name, false, 0, null, values, labels, null, null)); }
protected void InsertPropertyValue(FieldValue field, Dictionary <Type, object> targets) { Type t = Type.GetType(field.CacheName); PXCache cache = Base.Caches[t]; object target = targets[t]; PXStringState state = InitValueFieldState(field) as PXStringState; if (state != null) { if (state.AllowedValues == null || !state.AllowedValues.Any() || state.AllowedValues.Count() == 1 && field.AttributeID == null) { return; } if (state.AllowedValues.Count() == 1) { field.Hidden = true; field.Value = state.AllowedValues[0]; } else if (target != null) { state.Required = true; object value = cache.GetValueExt(target, field.Name); if (value is PXFieldState) { value = ((PXFieldState)value).Value; } field.Value = value != null?value.ToString() : null; } } Base.Caches[typeof(FieldValue)].Insert(field); }