Let's simplify publishing new NuGet packages for x++ builds
You are here
Form Control Lookup without a Data Source
There are rare instances where you want to have a form that has most of the functionality of a form that uses data sources but you can't ( or won't ) use datasource. This will very breifly walk you through creating a control that doesn't have a data source but still have a lookup and a "go to main table" ref. In this example, we will be creating a control that is meant to contain an ItemId.
First, Create a form control of type "String Edit" and set its "AutoDeclare" attribute to "Yes" and also set its "LookupButton" to "Always".
Now you have your control that we will be working it. Name and label it whatever you like. Go to the methods for that control, right-click and override the lookup function.
Add the following code to that method:
public void lookup()
{
SysTableLookup sysTableLookup; // systemclass to create //customlookup
Query query;
QueryBuildDataSource qbd;
;
sysTableLookup = SysTableLookup::newParameters(tablenum(InventTable), this);
// Construct query on the table,
// whose records you want to show as lookup.
query = new Query();
qbd = query.addDataSource(tablenum(InventTable));
// add the fields to the lookup list
sysTableLookup.addLookupfield(fieldnum(InventTable,ItemId));
sysTableLookup.addLookupfield(fieldnum(InventTable,ItemName));
// pass the query as parameter
// system will show the records in the lookup
// as per your query
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}The lines in yellow will be the only ones that change based on what you are looking up and what you want to display in the lookup. For us, ItemId and ItemName are fine. You now have a lookup, but no "Go to Main Table" functionality, which can be pesky because that is a feature I rely on quite a bit to move around in AX. So, now to add the "Go to Main Table" functionality. In the Methods for the control, override jumpRef. Add the following code:
public void jumpRef()
{
Args args;
MenuFunction menuFunction;
;
args = new Args();
menuFunction = new MenuFunction(menuitemDisplayStr(InventTable), MenuItemType::Display);
args = new Args(menuFunction.object());
args.caller(element);
menuFunction.run(args);
}The line in yellow will be the only one that changes based on what the main table is. And there you have it. A control on a form with no data source with a lookup and a "Go To Main Table" function. There are additional things that can be done with the args object to go to a specific record on the main form, or filter the entire form based on the selected ID's value.











