My Goal: To get a field from the PO Header (Plant_c) and copy it to the AP Invoice Header.
What I have done is this:
On the AP Invoice Entry menu I have created an FKV for POHeader.
I have never used an FKV before, so I hope I did it correctly…The columns do show up under Custom Columns, including the field I am looking for, which is Plant_c.
I then set an AfterFieldChange event on APInvHed, to try and catch when the REFPONum field changes.
private void APInvHed_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
switch (args.Column.ColumnName)
{
case "REFPONum":
MessageBox.Show(string.Format("APInvHed_AfterFieldChange: {0}", args.Row["REFPONum"]));
string POPlant_ID = edvPOHeader.dataView[edvPOHeader.Row]["Plant_c"].ToString();
MessageBox.Show(string.Format("POPlant_ID is set to: {0}", POPlant_ID));
break;
}
}
That event fires, and the first message box appears with the PO Num, then an error appears:
I am assuming that the edvPOHeader DataView has not been populated at this point.
With all of that being said, am I going about this the wrong way? I look into using a Method Directive, but I couldn’t find a method that fires when a new PO is loaded into the AP Invoice Header. The closest I found was on APInvoice.ChangeRefPONum, but that seems to hold the PONumber that was in the field (in this case, it was 0 from when I clicked the ‘NEW’ button.
I ran a trace to see what methods were called when I added the PO to the AP Invoice, and ChangeRefPONum is the only one that fired, so again, I am back to square one.
So my question is: Where did I go wrong here? What am I missing/overlooking to get a record from the PO Header on the AP Invoice Entry?