Hello everyone,
There is a form called InventNonConformanceTableCreate that I have added a new field to
The datasource of that form is InventNonConformanceTable
I created a new EDT and new field called TCI_InventProblemSubTypeId
The information for this field is in a table called TCI_InventProblemSubType which has the following fields:
Description
ProblemTypeId (related to table InventProblemType)
ProblemSubTypeId
Here is what it looks like on the form
What I'm trying to accomplish is overwriting the lookup for that Problem subtype so that it only shows the subtypes that are related to the chosen Problem Type.
I've done this before on a form we created which made it easy. I could right-click on the methods of the field in the datasource and overwrite the lookup. Now I'm not sure how to do this correctly.
I've tried a few different ways but so far nothing has worked.
This is my code from the other form that we created that works great
[DataField] class InventLocationId { ////// /// /// /// public void lookup(FormControl _formControl, str _filterStr) { //Specify the name of the table the lookup should show data from. SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(InventLocation), _formControl); //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(InventLocation)); queryBuildRange = queryBuildDataSource.addRange(fieldNum(InventLocation,InventSiteId)); queryBuildRange.value(queryValue(TCI_ItemTable.InventorySite)); //Specify which fields should be shown in the lookup form. // field returned is the first field referenced sysTableLookup.addLookupfield(fieldNum(InventLocation, InventLocationId)); sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); } }
Now I can easily adjust this code to look at the right tables and return the right fields, but where do I put this to get it to run?
Hey everyone,
I had another example on a form with multiple tabs and I needed to do a lookup of a field. The problem is, that field was in many tabs so I could have wrote code for every control I found, but I didn't find that very efficient. In a perfect world, I would put the lookup on the datasource field and that way it will happen no matter where it is.
So first I found this article which started me in the right direction
Next I needed to make a lookup method, so here is my code
First I created the Override Class
public class InventNonConformanceTableFormExtensionOverrides { protected void new() { } public static InventNonConformanceTableFormExtensionOverrides construct() { return new InventNonConformanceTableFormExtensionOverrides(); } public void TCI_InventProblemSubTypeId_OnLookup(FormStringControl _callingControl) { //Specify the name of the table the lookup should show data from. SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(TCI_InventProblemSubType), _callingControl); FormRun formRun = _callingControl.formRun(); FormDataSource dataSource_ds = _callingControl.formRun().dataSource(); InventNonConformanceTable inventNonConformanceTable = dataSource_ds.cursor(); //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(inventNonConformanceTable.InventTestProblemTypeId)); //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(); } }
Next created the Form Handlers Class
public class InventNonConformanceTable_Form_Handlers { ////// /// /// /// [FormDataSourceEventHandler(formDataSourceStr(InventNonConformanceTable, InventNonConformanceTable), FormDataSourceEventType::Initialized)] public static void InventNonConformanceTable_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e) { var overrides = InventNonConformanceTableFormExtensionOverrides::construct(); sender.object(fieldNum(InventNonConformanceTable, TCI_InventProblemSubTypeId)).registerOverrideMethod(methodStr(FormDataObject, lookup), methodStr(InventNonConformanceTableFormExtensionOverrides, TCI_InventProblemSubTypeId_OnLookup), overrides); } }
Now the lookup runs for every control attached to the field which is exactly what I wanted.
Thanks for all your help! It is now working as expected!
Setting the Auto declaration to yes will work if its COC.
To get form control values using event handler then refer to the below code.
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("Name of the control"); qbr.value(queryvalue(controlName.valueStr());
Thanks,
Girish S.
Hi Girish,
I was able to do what you said, and create a new group to replace the other. Then I put in the following code for my control
As you can see in the image, I hardcoded a queryvalue, just to see if it worked and it worked perfect.
So now, I want to take the value of the control called InventNonConformanceTable_InventTestProblemTypeId and use that value as my queryvalue.
I set the autodeclare on the control to Yes, and then put in InventNonConformanceTable_InventTestProblemTypeId.valueStr() in my queryvalue, but it tells me that InventNonConformanceTable_InventTestProblemTypeId has not been declared. I also tried InventNonConformanceTable_InventTestProblemTypeId.value() but the same error is coming up.
What should I be doing differently to get that value?
First check whether the lookup code for that control is working.
If its working we can check about the position of the control.
For the control to be on the specific group there is one work around.
You can hide the existing group and create new group with all the controls including your custom controls.
That's the only workaround you have.
Thanks,
Girish S.
Girish,
You are right. How I got that control added to the form was by creating a table extension of InventNonConformanceTable and adding the field to the field group
That is what automatically made it show up on the form
If I add the control to the form on it's own and then take that event handler, it works, but the control is completely off where it should be on the form
And here is where they are on the form
I really need it in the first spot for it to make sense, but I also need to lookup to work. I haven't tried my lookup code yet.....do we get that working first and then worry about the position of the control, or should we get the control in the right spot, and then worry about the code?
If its in same model, controls added to the extended form will be bold in color.
But in your screenshot the control and group is not bold. I am not sure the control and the event handler code is in same model.
Try removing the field groups and manually add the controls and check.
Also rename the control name and then copy the lookup event handler.
Thanks,
Girish S.
Hi Giresh,
Everything is in the same model.
I removed the event handler code from the class and also deleted the other class with the extension of the datasource field.
I then did a build and got no errors
I went into the form, found my control (which is in a field group), right-clicked on the OnLookup event for it and chose Copy event handler method
I pasted that method into my class
I do a build and get this error
Does your extension form, and event handler is in same model or in different model.
Please remove the code in the event handler class and then try building the project.
After successful build, paste the copied event handler code.
Thanks,
Girish S.
I haven't written anything because it won't compile
Here is my code
public class InventNonConformanceTableCreate_Form_Handlers { ////// /// /// /// [FormControlEventHandler(formControlStr(InventNonConformanceTableCreate, CreateInformation_TCI_InventProblemSubTypeId), FormControlEventType::Lookup)] public static void CreateInformation_TCI_InventProblemSubTypeId_OnLookup(FormControl sender, FormControlEventArgs e) { info("got here"); } }
And here is the build error
André Arnaud de Cal...
291,969
Super User 2025 Season 1
Martin Dráb
230,842
Most Valuable Professional
nmaenpaa
101,156