Note since no version was specified my example was coded against 2020r2
The following is an example that updates an Invoice/Memo's Description to the Location's CD and Descr fields [CD: Descr] when the location is changed on the Invoice/Memo. I believe the function you're looking for is PXSelectorAttribute.Select<SELECTOR_FIELD>(SELECTOR_FIELD_CACHE, SELECTOR_FIELD_RECORD) AS SELECTOR_TARGET_DAC
.
public class ArInvoiceEntrySoExt : PXGraphExtension<ARInvoiceEntry>
{
#region Event Handlers
#region ArInvoice
public virtual void _(Events.FieldUpdated<ARInvoice.customerLocationID> e, PXFieldUpdated del)
{
var inv = e.Row as ARInvoice;
del?.Invoke(e.Cache, e.Args);
if (inv != default)
{
var loc = PXSelectorAttribute.Select<ARInvoice.customerLocationID>(e.Cache, inv) as Location;
e.Cache.SetValueExt<ARInvoice.docDesc>(inv, string.Format("{0}: {1}", loc?.LocationCD, loc?.Descr));
}
}
#endregion
#endregion
}
An alternative, you can use PXSelectorAttribute.GetField(SELECTOR_FIELD_CACHE, SELECTOR_FIELD_RECORD, "SELECTOR_FIELD_NAME", SELECTOR_FIELD_VALUE, "SELECTOR_TARGET_FIELD_NAME")
to get a specific field from the selector's target record. As an example, the following code does the same thing as above using this alternative method:
public class ArInvoiceEntrySoExt : PXGraphExtension<ARInvoiceEntry>
{
#region Event Handlers
#region ArInvoice
public virtual void _(Events.FieldUpdated<ARInvoice.customerLocationID> e, PXFieldUpdated del)
{
var inv = e.Row as ARInvoice;
del?.Invoke(e.Cache, e.Args);
if (inv != default)
{
var loc = PXSelectorAttribute.Select<ARInvoice.customerLocationID>(e.Cache, inv) as Location;
e.Cache.SetValueExt<ARInvoice.docDesc>(inv, string.Format("{0}: {1}",
PXSelectorAttribute.GetField(e.Cache, inv, "customerLocationID", inv.CustomerLocationID, "LocationCD"),
PXSelectorAttribute.GetField(e.Cache, inv, "customerLocationID", inv.CustomerLocationID, "Descr")));
}
}
#endregion
#endregion
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…