1

I need to fill a field "description" from other field in a screen Acumatica. The problem is that one of the other field contains the identifier of the DAC but I have to retrieve the description and not the identifier.

I tried to do this with a Fluent BQL query in an Event Handler in order to retrieve the single result. var Feurname = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Current<APInvoice.vendorID>>>>.Select(this, BAccount.acctName).First().GetItem();

I have the following error when I test the code : \App_RuntimeCode\APInvoiceEntry.cs(97): error CS0119: 'BAccount.acctName' is a type, which is not valid in the given context

\App_RuntimeCode\APInvoiceEntry.cs(97): error CS0120: An object reference is required for the non-static field, method, or property 'PXSelectBase.Select(params object[])'

Thanks for your help!

3 Answers3

1

You need to retrieve the whole BAccount object and then take the AcctName properties value instead. So it will be something like below:

BAccount account = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Current<APInvoice.vendorID>>>>.Select(this);
var Feurname = (account?.AcctName)?? "";
Samvel Petrosov
  • 7,580
  • 2
  • 22
  • 46
0

You have done couple of mistakes here,

  1. When you need to pass a value to PXSelect<>, you should not pass types (starting with a simple letter). You should pass the DAC property name (starting with a capital letter). In your case BAccount.acctName is the type and property is BAccount.AcctName. Therefore the error message is correct.
  2. In your PXSelect<> query, you have not specified any field with Required<>. You have only specified fields with Current<>. You only need to pass parameters to .Select(this, ...) if you have Required<> in your PXSelect<>. If you have Current<>, framework will auto replace current value, then you don't need to pass parameters.

Both solutions below will return the BAccount Object:

  1. Assuming that your APInvoice has current values loaded. then remove the BAccount.acctName.
var Feurname = PXSelect<BAccount,Where<BAccount.bAccountID,Equal<Current<APInvoice.vendorID>>>>.Select(this);
  1. If your APInvoice current is not set, then you can pass the parameter to load BAccount. By replacing it with Required<>, then pass the correct parameter to Select(this, ...).
var Feurname = PXSelect<BAccount,Where<BAccount.bAccountID,Equal<Required<BAccount.bAccountID>>>>.Select(this, ...Parameter here...);
Kasun
  • 196
  • 1
  • 14
  • I just want to retrieve the value of the field BAccount.AcctName but I don't need to pass parameters. I should have only 1 row as a result of the query with the current value. var Feurname = PXSelect>>>.Select(this); -->Error is CS0120 'An object reference is required for the non-static field, method, or property PXSelectBase.Select(params object[])' – Lionel PARIS Oct 28 '22 at 13:45
  • @LionelPARIS Please provide more information on your primary DAC, Graph and, view of APInvoice (if it is not the primary DAC) – Kasun Oct 31 '22 at 07:55
  • I added the event handler in an extension of the APInvoice Graph. I don’t have modified anything else In the DAC nor in the graph. – Lionel PARIS Nov 01 '22 at 09:16
-1

So I succeeded by writing the query with LINQ instead of BQL with the following code in the event Handler. Thanks to the contributors. I would be curious to know to do the same with BQL/F-BQL.

var row = e.Row;
VendorMaint graph = PXGraph.CreateInstance(); var query1 = (from p in graph.Select() where p.BAccountID == row.VendorID select p.AcctName).ToList(); string feurname = ""; if (query1.Count > 0) { feurname = Convert.ToString(query1[0]); } else { feurname = ""; } row.DocDesc = feurname;

  • This is not encouraged in when you can get data from a BQL query. Since you can get data from BQL or fluent BQL, you should use that. Try to fix the error in BQL query – Kasun Oct 31 '22 at 07:54