Lionel PARIS
Lionel PARIS

Reputation: 31

Acumatica retrieve boolean User Field from Customer

I want to fill automatically a checkbox in SOOrder screen. The value of the checkbox is stored in Customer/BAccountExt. I don't know how to fill this checkbox after having chosen the customer in SOOrder screen.

The code I tried below works with other graphs but with Customer/BAccount one.

    protected void _(Events.FieldUpdated<SOOrder,  SOOrder.customerID> e)
    {
        SOOrder row = e.Row;
        SOOrderExt sOOrderExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(row);
    
        BusinessAccountMaint graph = PXGraph.CreateInstance<BusinessAccountMaint>();

        //**The next line doesn't works**
        BAccountExt baccountExt = PXCache<BAccount>.GetExtension<BAccountExt>(baccount);

        var query = (from p in graph.Select<PX.Objects.CR.BAccount>() where p.bAccountID == row.customerID select p.usrBC.ToList();
        sOOrderExt.UsrBonCde = Convert.ToBoolean(query[0]);
     }

Upvotes: 0

Views: 49

Answers (1)

Zoltan Febert
Zoltan Febert

Reputation: 1033

Try this code, it gets the cache extensions in a slightly different way:

    protected void _(Events.FieldUpdated<SOOrder.customerID> e)
    {
        var row = (SOOrder)e.Row;
        var soOrderExt = row?.GetExtension<SOOrderExt>();
        if (soOrderExt == null) return;

        var bAccount = (BAccount)SelectFrom<BAccount>
            .Where<BAccount.bAccountID.IsEqual<@P.AsInt>>
            .View.Select(Base, e.NewValue);

        var bAccountExt = bAccount?.GetExtension<BAccountExt>();
        soOrderExt.UsrBonCde = bAccountExt?.UsrBonCde;
    }

 

Upvotes: 0

Related Questions