Create Purchase Order Form - Vendor Dropdown

Hi all,

I am trying to teach myself simple development in AX and am trying to do the following.

  1. I have created a new field on vendtable called RC_Approved (YesNo Enum)

  2. When I create new purchase order I would like to filter the dropdown to only show records from the vendor table where the above value is set to yes)

I have done the following:

  1. on the init method of the form I have:

QueryBuilderRange ApprovedVendorQBR;

  1. on the Init method of the datasource (PurchTable) I have:

ApprovedVendorQBR = this.query().dataSourceName(‘VendTable’).addRange(fieldnum(VendTable,RC_Approved));

  1. I have created an excecutequery method on the datasource with

public void executeQuery()

{

;

ApprovedVendorQBR.value(queryvalue(NoYes::Yes));

super();

}

When I execute the form I get the following stacktrace

Error executing code: object not initialsed → (c)\classes]]datasourneName(c)\forms\purchcreateorder\data sources\purchtable\methods\init

I assume I need to set up a variable or something connecting purchtable and vendtable

please help if you can

My guess is that you call your code in init() before super() and therefore datasources are not yet initialized. If you’re not sure what’s happening, step through the code in debugger (sometimes it’s also useful to split a chain of calls to see where exactly it fails).

if you need this lookup for new POs you can override the lookup method for vendor field.

By doing this you can see only those vendor for whom RC_Approved value is set to Yes.

OK, how do I override the method?

I know it’s probably simple (read stupid) questions but I am very new in this… I should probably take some lessons in c#…

Right-click a Methods node in AOT, click Override method and choose a method of the parent class to be overridden. This works everywhere in AX - for data source fields, form methods, classes and so on.

I don’t seem to be able to get this to work with the above query and I am still totally blank as to the over ride method talk giving me what I need.

as stated above I get the object not initialised on the init method on the data source. The data source on the form is purchtable but I am trying to create a query based on vendtable. Can that be where the problem lies?

As I said my task is to filter the vendor drop down on the create purchase order form based on a yes no enum on the vendor table.

Your code refer to a datasource called VendTable:

this.query().dataSourceName('VendTable').addRange(fieldnum(VendTable,RC_Approved));

If it doesn’t exist (“The data source on the form is purchtable…”), you’ll get an error. That shouldn’t be surprising.

As a green, self paced leaner everything is surprising :slight_smile: Well at least I got to that myself as well…

Now time for me to find out how link back to Vendtable on the purchtable data source

As I already recommended in my first answer, you should split the calls and check them one by one. Otherwise you’re just complicating your work - and struggle with getting things done.

If you did so, your question would be “Why this.query().dataSourceName(‘VendTable’) returns null?” instead of “Why am I getting some error in init()?”. It would be much clearer where is the problem.

Also, don’t refer to query datasources by name - you often don’t know it. What if it was ‘VendTable_1’? I prefer dataSourceTable(tableNum(VendTable)).

About adding VendTable - just drag VendTable to form datasources, set JoinSource to PurchTable and LinkType to what you need (e.g. InnerJoin). AOT is full of examples.

Thanks a lot Martin,

I hear you. I am trying to learn and don’t want to come across stupid but by asking and trying is the way I am going so I do appreciate your feedback even though you come across a bit blunt [;)] but all good. I can handle it…

Your last post will definitely assist me.