I have a form with a grid. I have a query I've created in the AOT that's assigned to the grid.
At runtime I want to be able to dynamically assign the range. How do I do this?
It's easy enough with a query built in X++ (QueryBuildDataRange), but I can't figure out how to do it with an AOT query.
*This post is locked for comments
As you have already got your value in init() method of child form(Lookup). Now you can do following
Declare an object of QueryBuildRane in class node of form
QueryBuildRange qbrSampleName;
In the init() method of Datasource of form initialize QueryBuildRane after supr();
public void init()
{
super();
this.query().dataSourceTable(tableNum(NameofYourTable)).addRange(fieldNum(NameofYourTable,FieldName));
qbrSampleName = this.query().dataSourceTable(tableNum(NameofYourTable)).addRange(fieldNum(NameofYourTable,FieldName));
}
Now in execute query of data source, provide value of Range, before super();
void executeQuery()
{
if(ValueYouGotAsParmeter)
qbrSampleName.value(queryValue(PassHereValueToFilter));
else
criteriaPropertyId.value(SysQuery::valueUnlimited());
Super();
}
I figured out how to pass the value. The value I'm passing is a LogisticsLocationRoleType.
in the lookup() I have:
args = new Args(identifierStr("myLookupForm"));
cont = [LogisticsLocationRoleType::Consignment_IN];
conClassObj = new ContainerClass(cont);
args.parmObject(conClassObj);
formRun = classFactory::formRunClassOnClient(args);
Then, in the lookup form's init(), I'm doing:
xArgs args;
container cont;
ContainerClass conClassObj;
super();
if(element.args())
{
args = element.args();
conClassObj = args.parmObject();
cont = conClassObj.value();
roleType = conPeek(cont, 1);
}
element.selectMode(lookupControl);
So that works great!
So that gets me half way there. The only thing I need to do now is to set the range on the query in the datasource. How do I accomplish that?
attach your XPO here on community or somewhere, I will look into details what you are trying to do
But I can't use SysTableLookup::getCallerStringControl() because it's not a SysTableLookup.
I have the FormControl object in the lookup() function (assigned to _formControl in the code from my previous post). How do I pass that to myLookupForm?
if you are using lookup form you can always get calling control using below syntax and you can put your custom logic based on calling control
callingControl = SysTableLookup::getCallerStringControl(element.args());
I feel more comfortable to use lookup by x++ code by placing code on table level in such case, Doing that way you can pass parameters as below
public void lookup(FormControl _formControl, str _filterStr)
{
TableName::lookupStaticMethodName(
_formControl,
AnyValueToPass);
}
You may have a look at next presentation to know what will suite you best.
While you can have a join in a query and create ranges on those joined tables, you can only display fields from a single table in a SysTableLookup (the one passed to newParameters()).
As for your description of what to do, I'm confused.
I have my main form which has all my data and the controls (let's call it myMainForm).
Then I have my lookup form (let's call it myLookupForm).
I override lookup() in the data source on the field associated with the controls I'm displaying the lookup for. The code look like this:
FormRun formRun;
Args args;
args = new Args(identifierStr("myLookupForm"));
formRun = classFactory::formRunClassOnClient(args);
formRun.init();
this.performFormLookup(formRun, _formControl);
How do I pass my parameter to myLookupForm?
If your lookup and controls are all on same form, you can always get values of controls in current form/context. It seems you have written code of lookup not on the form, but somewhere on the table level. You can pass FormStringControl as 1st parameter, in case if you lookup method is on any table.
But if your lookup method is on the form, you can take current values of controls by setting AutoDeclartion= True for those controls.
This way based on caller you can change lookup code.
Regarding your 2nd point, which is about usage of SysTableLookup, I would say you can use it in a way by creating a view by joining two tables, if that suits you.
Actually, it's a lookup and it's called by 2 different controls and the what I'm looking for depends on which control is calling the lookup.
And the reason I can't use SysLookup is that I need to display fields from 2 different tables in the query.
do you want to filter based on current selection by user, where user will select a value?
Yes, I've looked at Google and through all the examples I've seen, I run into some issue or another that I can't seem to get around.
The example you linked is one of them. They do the work in init(), but init() takes no parameters, so how do I pass the information I need to filter on?
André Arnaud de Cal...
292,162
Super User 2025 Season 1
Martin Dráb
230,962
Most Valuable Professional
nmaenpaa
101,156