plz somebody help me
You weren't very generous in words, but I assume that you have a form control bound to a data source and you would like to sometimes show the field as mandatory, depending on values of some other fields in the same record.
If my description is correct, try to write it by yourself next time.
If it isn't, you see that you have to provide more details if you want to get an answer.
Assuming that I understand what you want, the answer is that you can override the active() method of the data source and set the mandatory property to true of false for the active record based on any condition you like.
Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog
I did using the below code in active() but no changes occur
I made a quick demo based on Martin's suggestion and I can verify that it works on my DEV machine.
If you can't figure out what's wrong, consider posting some screenshots of your implementation here.
My blog | PBC
This forum post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.
if your control is bound to a datasource field (i.e. your control has a table field behind)
you should not use the code as you are using. you should write code as under
Referring control directly [control.mandatory(true);] is not good because of following reason:
Referring to control is only suggested when control is not bound to Dataset. In that case AutoDecleration property of control should be YES.
I have to add that code in modified() method of the field or what?? And ledgerjournaltrans_ ds is that a buffer or what/?? Plz reply to me ASAP
modified() method of the field is executed when the user changes the value of the field. How would it help you to set the field as mandatory before user actually starts changing the value? It's no way to go.
ledgerjournaltrans_ ds is an object representing a form data source. As always, you'll learn more about them in the documentation: Form Data Sources.
you have to add code in active method of DataSource after super();
Better would be if you put your code at end of standard AX code.
ledgerjournaltrans_ds represents your datasource (see your previous reply you have it there)
I added that code but nothing works ;it just keeps that field not mandatory in modified() of selected field
Can you please show your code?
and where you have written your code?
the method is that the modified method of selected control
why are you coding under modified method of selected control.???
I hope you can read previous replies, again
you have to write this code inside active method of Datasource.
Expand your DataSource and see if active method is there, code there after super.
if active method is not there, overwrite it
I did but also nothing changes , mandatory field wasn't set in all lines
which lines you are talking about to Lines of journal or Line of journal header?
lines of journal header; when I select field values ,the control that I need to validate is mandatory to all lines
Why didn't you tell on the beginning that my interpretation of your requirement is not correct and you want it for all lines and not "to sometimes show the field as mandatory, depending on values of some other fields in the same record"? I explicitly asked you for then confirmation.
You're wasting time of all of us. To avoid it in future, people may decide ignore your questions. You really should do better job in providing information in your own interest.
Set the Mandatory property to True either on the form data source (if it's form-specific behavior) or the table field.
What you see is the expected behavior. The Mandatory property is set for the field, i.e. it always applies to all records. What we tried to explain to you is how you can workaround this by changing it on an line activation, so you have a chance to change the behavior for *the current* record.
It seems that you've chosen wrong design from the beginning but we couldn't give you any advice, because you didn't tell us anything about your actual requirement.