I 'm working on a customization where I need to allow users to select a DAC (for example Vendor, Contact, Location, etc.) and then dynamically display the list of available fields for that DAC so the selected field can be saved for later processing (similar to a generic Inquiry screen). The DAC is resolved dynamically at runtime, and the requirement is to list all usable fields (including standard DAC fields and extension Usr* fields) without hardcoding them. I tried to find a way by investigating Generic Inquiry screen, but I was unable to find working solution
#region FullDACName
[PXDBString(255, IsFixed = true, InputMask = "")]
[PXUIField(DisplayName = "Full DACName")]
[PXStringList(
new[]
{
"PX.Objects.AP.VendorR",
"PX.Objects.CR.Location",
"PX.Objects.CR.Contact",
"PX.Objects.AP.BAccount"
},
new[]
{
"Vendor",
"Location",
"Contact",
"BAccount"
}
)]
public virtual string FullDACName { get; set; }
public abstract class fullDACName : PX.Data.BQL.BqlString.Field<fullDACName> { }
#endregion
#region DACFieldName
[PXDBString(128, IsFixed = true, InputMask = "")]
[PXUIField(DisplayName = "DACField Name")]
[PXStringList(new string[] { null }, new string[] { "" }, ExclusiveValues = false)]
public virtual string DACFieldName { get; set; }
public abstract class dACFieldName : PX.Data.BQL.BqlString.Field<dACFieldName> { }
#endregionThis is My custom DAC fields. I can hardcode the DAC list. That is fine. I just need to List fields of the selected DAC
I tried to set fields using events as bellows. Nothing works yet.
protected virtual void _(Events.FieldSelecting<ESEftsureAPIMapper, ESEftsureAPIMapper.dACFieldName> e)
{
if (e.Row == null)
return;
var values = new List<string>();
var labels = new List<string>();
if (!string.IsNullOrWhiteSpace(e.Row.FullDACName))
{
Type dacType = PXBuildManager.GetType(e.Row.FullDACName, false);
if (dacType != null && typeof(IBqlTable).IsAssignableFrom(dacType))
{
PXGraph graph = e.Cache.Graph;
if (!graph.Caches.ContainsKey(dacType))
{
graph.Views.Add(dacType.Name,
new PXView(graph, false, BqlCommand.CreateInstance(dacType)));
}
PXCache cache = graph.Caches[dacType];
cache.CreateInstance();
foreach (string field in cache.Fields)
{
values.Add(field);
labels.Add(field);
}
//PXStringListAttribute.SetList<ESEftsureAPIMapper.dACFieldName>(cache, e.Row, values.ToArray(), labels.ToArray());
}
}
e.ReturnState = PXStringState.CreateInstance(
e.ReturnState,
255,
null,
nameof(ESEftsureAPIMapper.dACFieldName),
false,
1,
null,
values.ToArray(),
labels.ToArray(),
true,
null
);
}
protected virtual void _(Events.RowSelected<ESEftsureAPIMapper> e)
{
if (e.Row == null)
return;
var row = e.Row;
var cache = e.Cache;
if (string.IsNullOrWhiteSpace(row.FullDACName))
return;
Type dacType = PXBuildManager.GetType(row.FullDACName, false);
if (dacType == null || !typeof(IBqlTable).IsAssignableFrom(dacType))
return;
PXCache dacCache = this.Caches[dacType];
List<string> values = new List<string>();
List<string> labels = new List<string>();
foreach (string field in dacCache.Fields)
{
values.Add(field);
PXFieldState state = dacCache.GetStateExt(null, field) as PXFieldState;
labels.Add(state?.DisplayName ?? field);
}
// Optional: add empty
values.Insert(0, string.Empty);
labels.Insert(0, string.Empty);
PXStringListAttribute.SetList<ESEftsureAPIMapper.dACFieldName>(
cache,
row,
values.ToArray(),
labels.ToArray()
);
}