Hello community!
I'm trying to make a field in a form grid to be only filled with a list look up options and not be able to enter values manually and let the user type whatever data he wants.
I want to force him to use the look up list.
How can I achieve that?
I made the look up list by overriding the lookup method of the form field control method.
Thanks in advance!
Hi Momochi,
I'm not sure if it's a good idea to disable this feature as it's quite useful in case if you already know the value and you don't need to search in the lookup and even to open lookup. Maybe you should think about proper validation of input value in validateField method.
If the field in question is in a custom table, the best practice way to ensure that no other values can entered in forms is to define a relation on the field to the other table.
If the field in quesion is a standard field, then this should be possible with the "Lookup Only" property of the field control. I have not tried it myself.
Hello Sergei,
is Using ValidateField will thorw the error after trying to save the record?
ValidateField is executed when value is changed for the field and users will see the error before they save the record or leave the field.
Hello Anton,
It's a custom form with custom tables. But Since I'm working on a different module, will it work if I defined a new relation for the table in another module using extension? or this is not a good practice.
Thanks for the tips.
I'm sorry I'm new in this area....
I see it's a table event.
Which line of code should I use to throw an error after checking the value?
Thanks.
I think you need to decide first where to apply the change: your model or model where table was created. Event handlers, extensions and CoC increase complexity of the code.
Here is one one of the example how to use event handlers, but the idea is the same for direct method change on the table or CoC method.
d365solution.blogspot.com/.../how-to-write-validatefield-method-in.html
Also, you can use validate methods on the form if you want to restrict validate logic only for one form.
Hi Sergei,
Thanks for the info!
Yes, I would like it to be on a specific form only.
I see there are two methods for validation: onValidated and onValidating.
I'm totally confused actually on what's the difference and which one should I use...
and about the example you posted, if I wanted to throw an error I should use args.setReturnValue(false)?
I'm sorry for taking your time.
I tried using both OnValidating and onValidated events, and I used checkFailed() method to throw the error as shown in the example you posted.
But once the warning sign is shown on the field, it won't go even if I posted correct data again...
Screenshot:
is something wrong with how I checked the value?
after running the debugger it seems that sender.formRun().dataSource("datasource").cursor(); didn't get the value entered.... it shows as null, though it has taken the other previous fields.
EDIT: the debugger shows that it's stuck with the first value entered and always checks using first value entered no matter how many times I change it
Both onValidated and onValidating fires before they take the new selection from the look up...
So should I look for other events?
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
CA Neeraj Kumar 1,964
André Arnaud de Cal... 823 Super User 2025 Season 2
Sohaib Cheema 564 User Group Leader