Woody
Woody

Reputation: 7

How to reference customer field which I created in AP301000

I have created a customer field on AP301000. The field works fine on screen. now I want this field to be populated after Vendor was selected, so I tried to customize business logic with code list this:

 protected void APInvoice_VendorID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
    {
      if(InvokeBaseHandler != null)
        InvokeBaseHandler(cache, e);
      var row = (APInvoice)e.Row;

      APInvoice.UsrVendorKey="test";
    }

but I got the following error:

'PX.Objects.AP.APInvoice' does not contain a definition for 'UsrVendorKey' in file : Code#APInvoiceEntry(56)

Upvotes: 0

Views: 342

Answers (2)

Gabriel
Gabriel

Reputation: 3783

Your code doesn't compile because you're trying to set a value to the class, rather than to an instance of this class. row is an instance of APInvoice. Furthermore, your custom fields are not directly added to APInvoice, so you need to retrieve the extension first before you can update a value. Assuming you used the customization manager to add your field, the extension class would usually be named APInvoiceExt. Full could would look something like:

protected void APInvoice_VendorID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
  if(InvokeBaseHandler != null)
    InvokeBaseHandler(cache, e);
  var row = (APInvoice)e.Row;
  var ext = cache.GetExtension<APInvoiceExt>();
  ext.UsrVendorKey="test";
}

Upvotes: 1

Brandon Renfro
Brandon Renfro

Reputation: 56

I would recommend that you read all of the technical documents, specifically the T300 course as it goes over the event model. There are a few issues with your code.

First, you should be using FieldDefaulting if you want the data to populate when selecting a vendor. FieldUpdating is for when you change the value of that field.

Second, you need to get your extension first before you can do anything with your UsrVendorKey field.

For Example, getting an SOOrder extension would look like this where SOOrderExt is the name of your DAC extension.

var currentOrder = Base.Document.Current.GetExtension<SOOrderExt>();

After you get the extension you can then use it to access your new fields

e.NewValue = currentOrder.UsrFieldName;

Upvotes: 1

Related Questions