I'm trying to run some lookup code on a form control but this control is part of a field group. I was able to run this same code on other controls that are not part of the group just fine but when I copy the event handler, it gives me an error saying the control is not found.
Here is my control
I copy the event handler for OnLookup and paste it in my class but then I get this
What do I need to do different in order to get this code to compile?
Okay, I will remove it from the field group. Thanks for your help!
Hi Andrew, I just replicated your issue by trying to use onLookup event of custom field in a field group. I have noticed that this issue occurs only for custom fields. You can check using OnLookup for 'Quarantine_QuarantineZoneId' control in InventNonConformanceTable form and compiler will not throw error, even though this field is in a field group.
I believe this is limitation on new fields and to fix it you have move the field out of the field group.
There is a thread on same issue, Check this out.
community.dynamics.com/.../form-control-is-not-found-in-form
Hi Mohit, have you had a chance to look at my code?
Here is my code. As you can see, I already have the lookup for another instance of the Problem Sub Type on a different tab. The thing is, the tab that I'm trying to get it to work on, the formcontrol is inside a field group like I mentioned. As soon as I add the code at the bottom, it give me the error
public class InventNonConformanceTable_Form_Handlers { ////// /// /// /// [FormControlEventHandler(formControlStr(InventNonConformanceTable, InventNonConformanceTable_TCI_InventRootSubTypeId), FormControlEventType::Lookup)] public static void InventNonConformanceTable_TCI_InventRootSubTypeId_OnLookup(FormControl sender, FormControlEventArgs e) { //Specify the name of the table the lookup should show data from. SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(TCI_InventRootSubType), sender); FormRun formRun = sender.formRun(); FormDataSource dataSoruce_ds = sender.formRun().dataSource(); //To get the buffer use below code. //TableName tableBuffer = dataSoruce_ds.cursor(); //To get control value refer to beloe code FormControl controlName = formRun.design().controlName("InventNonConformanceTable_TCI_InventRootTypeId"); //Cancel super FormControlCancelableSuperEventArgs event = e as FormControlCancelableSuperEventArgs; event.CancelSuperCall(); //Create a new query Query query = new Query(); QueryBuildDataSource queryBuildDataSource; QueryBuildRange queryBuildRange; //Specify the name of the table the lookup should show data from. queryBuildDataSource = query.addDataSource(tableNum(TCI_InventRootSubType)); queryBuildRange = queryBuildDataSource.addRange(fieldNum(TCI_InventRootSubType,TCI_InventRootTypeId)); queryBuildRange.value(queryValue(controlName.valueStr())); //Specify which fields should be shown in the lookup form. // field returned is the first field referenced sysTableLookup.addLookupfield(fieldNum(TCI_InventRootSubType, TCI_InventRootSubTypeId)); sysTableLookup.addLookupfield(fieldNum(TCI_InventRootSubType, Description)); sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); } ////// /// /// /// [FormControlEventHandler(formControlStr(InventNonConformanceTable, InventNonConformanceTable_TCI_InventProblemSubTypeId), FormControlEventType::Lookup)] public static void InventNonConformanceTable_TCI_InventProblemSubTypeId_OnLookup(FormControl sender, FormControlEventArgs e) { //Specify the name of the table the lookup should show data from. SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(TCI_InventProblemSubType), sender); FormRun formRun = sender.formRun(); FormDataSource dataSoruce_ds = sender.formRun().dataSource(); //To get the buffer use below code. //TableName tableBuffer = dataSoruce_ds.cursor(); //To get control value refer to beloe code FormControl controlName = formRun.design().controlName("InventNonConformanceTable_InventTestProblemTypeId"); //Cancel super FormControlCancelableSuperEventArgs event = e as FormControlCancelableSuperEventArgs; event.CancelSuperCall(); //Create a new query Query query = new Query(); QueryBuildDataSource queryBuildDataSource; QueryBuildRange queryBuildRange; //Specify the name of the table the lookup should show data from. queryBuildDataSource = query.addDataSource(tableNum(TCI_InventProblemSubType)); queryBuildRange = queryBuildDataSource.addRange(fieldNum(TCI_InventProblemSubType,ProblemTypeId)); queryBuildRange.value(queryValue(controlName.valueStr())); //Specify which fields should be shown in the lookup form. // field returned is the first field referenced sysTableLookup.addLookupfield(fieldNum(TCI_InventProblemSubType, ProblemSubTypeId)); sysTableLookup.addLookupfield(fieldNum(TCI_InventProblemSubType, Description)); sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); } ////// /// /// /// [FormControlEventHandler(formControlStr(InventNonConformanceTable, ProblemInformation_TCI_InventProblemSubTypeId), FormControlEventType::Lookup)] public static void ProblemInformation_TCI_InventProblemSubTypeId_OnLookup(FormControl sender, FormControlEventArgs e) { } }
Hi Andrew, I am able to access field in field group on form control in onlookup event handler. Please share your code, it might be issue there.
Hi Mohit, I looked at that link but I'm not sure how to do that.
That form control and field group is in an extension of that table that I created. Does that change how I should be calling it?
Hi Andrew,
For the error message, most likely you have placed your event handler code in a different package than your field group.
In this case you need to add package reference, otherwise your event handler package can't see the objects of the other package.
Hi Andrew, How about using form datasource field lookup instead of form design control
André Arnaud de Cal...
291,979
Super User 2025 Season 1
Martin Dráb
230,848
Most Valuable Professional
nmaenpaa
101,156