Question Status

Suggested Answer
Codehunter asked a question on 19 Mar 2015 5:19 PM

plz somebody help me

Reply
Suggested Answer
Martin Dráb responded on 19 Mar 2015 5:32 PM

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

Reply
Codehunter responded on 19 Mar 2015 5:56 PM

I did using the below code in active() but no changes occur

if(Ledgerjournaltable.category=="")

control.mandatory(true);

Reply
Dominic Lee responded on 19 Mar 2015 9:18 PM

Hi Codehunter,

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.

kind regards,

Dominic Lee

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.

Reply
Sohaib responded on 19 Mar 2015 11:39 PM

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

if(!LedgerJournalTrans.category)
    {
        LedgerJournalTrans_DS.object(fieldNum(LedgerJournalTrans,YourFieldName)).mandatory(true);
}
else
{
LedgerJournalTrans_DS.object(fieldNum(LedgerJournalTrans,YourFieldName)).mandatory(false);
}


 Referring control directly [control.mandatory(true);] is not good because of following reason:

  • you have to refer field multiple times, if its being used in design multiple time.

Referring to control is only suggested when control is not bound to Dataset. In that case AutoDecleration property of  control should be YES.

Reply
Codehunter responded on 20 Mar 2015 2:33 AM

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

Reply
Martin Dráb responded on 20 Mar 2015 2:48 AM

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.

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply
Sohaib responded on 20 Mar 2015 2:49 AM

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)

Reply
Codehunter responded on 20 Mar 2015 3:21 AM

I added that code but nothing works ;it just keeps that field not mandatory in modified() of selected field

Reply
Sohaib responded on 20 Mar 2015 3:27 AM

Can you please show your code?

and where you have written your code?

Reply
Codehunter responded on 20 Mar 2015 3:32 AM

the method is that the modified method of selected control

Modified()

{

if(LedgerJournaltable.Category=="Subcontractors")

{

LedgerJournalTable_ds.object(fieldnum(LedgerJournaltable,Ledger_worderid)).mandatory(true);

}

else

{

LedgerJournalTable_ds.object(fieldnum(LedgerJournaltable,Ledger_worderid)).mandatory(false);

}

}

Reply
Sohaib responded on 20 Mar 2015 3:35 AM

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

Reply
Codehunter responded on 20 Mar 2015 3:45 AM

I did but also nothing changes , mandatory field wasn't set in all lines

Reply
Sohaib responded on 20 Mar 2015 3:46 AM

which lines you are talking about to Lines of journal or Line of journal header?

Reply
Codehunter responded on 20 Mar 2015 3:58 AM

lines of journal header; when I select field values ,the control that I need to validate is mandatory to all lines

Reply
Suggested Answer
Martin Dráb responded on 20 Mar 2015 4:04 AM

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.

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply
Suggested Answer
Martin Dráb responded on 19 Mar 2015 5:32 PM

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

Reply
Suggested Answer
Martin Dráb responded on 20 Mar 2015 4:04 AM

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.

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply
Suggested Answer
Martin Dráb responded on 20 Mar 2015 5:15 AM

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.

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply