In this article, giving an example for defining the lookup using lookupReference method in simple way.
step 1 .
Override the lookupReference method on a required filed node in forms datasourse .
public Common lookupReference(FormReferenceControl _formReferenceControl)
{
return MytableToGetLookup::getlookup(_formReferenceControl );
}
Step 2 .
Define method on table from where you have to get the values in the lookup
public static Common lookupReceiptLayout(FormReferenceControl _ctl, SomeFilter _someFilter)
{
SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tablenum(RRPRReceiptLayout), _ctl, true);
Query query = new Query();
QueryBuildDataSource queryBDS;
MytableToGetLookup _mytableToGetLookup
;
// add the fields to show in the looup
sysTableLookup.addLookupfield(fieldNum(MytableToGetLookup , field1));
sysTableLookup.addLookupfield(fieldNum(MytableToGetLookup , field2));
queryBDS = query.addDataSource(tablenum(MytableToGetLookup )); //add datasourse
queryBDS.addRange(fieldnum(MytableToGetLookup , fieldToAddFilter)).value(_someFilter); // add filter
sysTableLookup.parmQuery(query);
_mytableToGetLookup = sysTableLookup.performFormLookup();
return _mytableToGetLookup ;
}
Dynamics AX will display the results of the query, based on the filter we've created. So the user will only be able to see what we want him to see, and so he'll only be able to select what we want. The problem is that if he types in an existing record in the control, even if does not get shown in our lookup, Dynamics AX will accept that.
To avoid that the user does in fact type in something we don't want, we'll have to override the validate method .
step 1 .
Override the lookupReference method on a required filed node in forms datasourse .
public Common lookupReference(FormReferenceControl _formReferenceControl)
{
return MytableToGetLookup::getlookup(_formReferenceControl );
}
Step 2 .
Define method on table from where you have to get the values in the lookup
public static Common lookupReceiptLayout(FormReferenceControl _ctl, SomeFilter _someFilter)
{
SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tablenum(RRPRReceiptLayout), _ctl, true);
Query query = new Query();
QueryBuildDataSource queryBDS;
MytableToGetLookup _mytableToGetLookup
;
// add the fields to show in the looup
sysTableLookup.addLookupfield(fieldNum(MytableToGetLookup , field1));
sysTableLookup.addLookupfield(fieldNum(MytableToGetLookup , field2));
queryBDS = query.addDataSource(tablenum(MytableToGetLookup )); //add datasourse
queryBDS.addRange(fieldnum(MytableToGetLookup , fieldToAddFilter)).value(_someFilter); // add filter
sysTableLookup.parmQuery(query);
_mytableToGetLookup = sysTableLookup.performFormLookup();
return _mytableToGetLookup ;
}
Dynamics AX will display the results of the query, based on the filter we've created. So the user will only be able to see what we want him to see, and so he'll only be able to select what we want. The problem is that if he types in an existing record in the control, even if does not get shown in our lookup, Dynamics AX will accept that.
To avoid that the user does in fact type in something we don't want, we'll have to override the validate method .
No comments:
Post a Comment