T-Rav
T-Rav

Reputation: 67

How to make Acumatica custom action update the current record

I'm trying to make a custom action update a custom field on the current record. Eventually I need to work through all the deatils to collect some data, but for now I just need to click the button and have it update the current record. More or less, I think I fail to understand how to get the data that would be in a row level event like this protected void SOOrder_RowSelected(PXCache cache, PXRowSelectedEventArgs e)

    public PXAction<PX.Objects.SO.SOOrder> LookupShipping;

    [PXButton(CommitChanges = true)]
    [PXUIField(DisplayName = "Lookup Shipping Rates")]
    protected void lookupShipping()
    {

      SOOrder TheRow = Base.Document.Current;

    }

Thanks in advance.

Upvotes: 0

Views: 1847

Answers (1)

Brian Stevens
Brian Stevens

Reputation: 1941

If you are trying to update custom fields...

First, you will want to connect to the DAC Extension via:

SOOrderExt sOOrderExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(TheRow);

Then you need to update the field value. Assuming you are in a Graph Extension, you will need to utilize "Base" to access the cache.

Base.Caches[typeof(SOOrder)].SetValueExt<SOOrderExt.usrCustomField>(TheRow, InsertValueHere);

Once you update all field values, you need to actually update the cache itself.

Base.Caches[typeof(SOOrder)].Update(sOOrderExt);

And don't forget to save the record, assuming this button should be a one-stop shop.

Save.Press();

If you are trying to simply update the values in the existing view, you can do it very easily.

TheRow.FieldName = InsertValueHere;
Document.Current.Update(TheRow);
Save.Press();

You can see some good alternatives to updating values in HB_Acumatica's answer to where I asked something similar... What is the proper way to update values of DAC's retrieved via PXResultset?

Upvotes: 1

Related Questions