Filter on Lookup Form

Hello All,

Just struggling with a look up form and wondering if someone could help me please. On my sales ledger form under sales Line Tab I have inserted a new field called Job id which is EDT. I am calling a lookup form on this field. The data source of this look up form is a table contains sales id, job id and name. I want to add filter on the sales id of this look up form.

So if user creates a new sales line select item number and when he clicks on job ID he can only see the record which is linked with the current sales id of sales line.

At the moment if user clicks on the field he see following values in look up form

Sales Id - Job Id - Name

SO7546 701 Futaba

SO7546 702 Futaba

SO7546 703 Futaba

SO7547 704 Futaba

SO7547 705 Futaba

SO7548 706 Futaba

As i am creating a sales line on Sales ID SO7547 so i only want to see this record in my look up form.

SO7547 704 Futaba

SO7547 705 Futaba

Kind Regards,

if it is a lookup form then you can write the code in Execute query of the Datasource and filter it. Pass the Salesid.

for Ex: SalesID

select * from LookupformDS where LookupformDS.SalesID = selectedSalesID

Hope it wil work


It is quite straight forward. You have to write a lookup method on the form something like this -

void lookupJobId(FormControl control)
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
SysTableLookup sysTableLookup;

//Create an instance of SysTableLookup with the form control passed in
sysTableLookup = SysTableLookup::newParameters(tablenum(), control);

//Add the fields to be shown in the lookup form

, ), true);
, ), false);

//create the query datasource
queryBuildDataSource = query.addDataSource(tablenum(

queryBuildRange = queryBuildDataSource.addRange(fieldnum(
, ));
queryBuildRange.value(enum2str(NoYes::Yes)); //Example of Enum value

//add the query to the lookup form

// Perform lookup

Hi Harish,

Could you please explain a bit because i am new to axapta my code is

public void lookup(FormControl _formControl)


Query query=new Query();

QueryBuildDataSource querybuildDataSource;

QueryBuildRange queryBuildRange;

SysTableLookup sysTableLookup;


sysTableLookup=SysTableLookup::newParameters(tablenum(JS_Serviceline), _formControl);






I am finding it a bit confusing to add filter .



I have done it .



I was just writing pseudo code. Then saw your post. Well done [:)]

you can code before sysTableLookup.parmQuery(query);


queryBuildDataSource.addSortField(fieldnum(Table, Field1));

queryBuildDataSource.addSortField(fieldnum(Table, Field2));

to filter duplicate field

HI Jahan

canu send me the code how u have done the filter, even i have tried ur code but my filter is not working, can u post the code for the form lookup filter…

i have created the Form EZNDeposits


Here i have Deposit Number & FD Number, in this form same customer number with different FD Numbers

IN my Second form see below


Here in the Cust NoFInal field i need to get the look up from the First form Custno & FD no, while lookup is displaying it should filter the data, suppose if i pick the CUS001, under this how many fd are displaying i need to fetch that data…

can u tell me how to write the code like this senario,.


Hi Ayesha,

I am new to AX, I am also stuck in same point Can you please send me the code.