Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
703 views
in Technique[技术] by (71.8m points)

acumatica - How to get Selector Substitute Key / Description values

Lets say I have a DAC record, like SOOrder, and I have a field like customerID, where there is a PXSelectorAttribute defined on an integer field, that has a SubstitueKey = typeof(Customer.acctCD) and Description = typeof(Customer.acctName). Is there some way that I can get the values of the substitute key / description field for that record without doing a PXSelect against the selectors table?

Thanks -Kyle

question from:https://stackoverflow.com/questions/65929345/how-to-get-selector-substitute-key-description-values

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...