web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to make a form datasource fields mandatory from a table method

(0) ShareShare
ReportReport
Posted on by

Hi All,

I have been customizing form (CustTable) and have created a group in it .  The group contains two fields from table (TaxInformationCustTable_IN) .

Now I have override the modiefiedvalue() method in (TaxInformationCustTable_IN). When I debug every thing goes well , I mean the flow is executing the line which will make / set the datasouce fields mandatory / allowedit property accordingly. But on form no effect is getting reflected , I mean the field's property on the form is getting changed neither getting mandatory not setting it's allow edit property.

please find the below code and let me know what am I committing wrong here:

public void modifiedFieldValue(FieldName _fieldName, int _arrayIndex = 1)
{
    // Azelis -->
    #isoCountryRegionCodes
    TaxInformationCustTable_IN  taxInfoCustTable;
    boolean                     boolActive;
    CustTable                   custDataSource;
    FormBuildDataSource         formBuildDataSource; 
    FormBuildDesign             formBuildDesign;
    FormRun                     formRun;
    Args                        args        = new Args();
    Form                        form        =new Form();
    DictTable                   dicTableID  = new DictTable(tableNum(TaxInformationCustTable_IN));
    FormDataSource              objFormDS   = new FormDataSource();
    super(_fieldName, _arrayIndex);
   
    formBuildDataSource = form.addDataSource(dicTableID.name());
    formBuildDataSource.table(dicTableID.id());
    formBuildDesign     = form.addDesign('Design');
    args.object(form);
    formRun = new FormRun(args);
    formRun.run();
    objFormDS = formRun.dataSource(1);
    switch(_fieldName)
    {
        
        
        case fieldStr(TaxInformationCustTable_IN, AZ_UnauthorizedDealer):

            if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoIN]))
            {
                
                if (this.AZ_UnauthorizedDealer == NoYes::Yes)
                {
                    objFormDS.object(fieldNum(TaxInformationCustTable_IN, AZ_RegistrationNumber)).mandatory(false);
                    objFormDS.object(fieldNum(TaxInformationCustTable_IN, AZ_RegistrationNumber)).allowEdit(false);
                    this.AZ_RegistrationNumber = '';
                }
                else if (this.AZ_UnauthorizedDealer == NoYes::No)
                {
                    objFormDS.object(fieldNum(TaxInformationCustTable_IN, AZ_RegistrationNumber)).mandatory(true);
                    objFormDS.object(fieldNum(TaxInformationCustTable_IN, AZ_UnauthorizedDealer)).allowEdit(false);
                    objFormDS.object(fieldNum(TaxInformationCustTable_IN, AZ_RegistrationNumber)).allowEdit(false);
                }
            }

        break;

        case fieldStr(TaxInformationCustTable_IN, AZ_RegistrationNumber):

            if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoIN]))
            {
                if (    this.AZ_RegistrationNumber == ''
                    &&  this.AZ_UnauthorizedDealer == NoYes::No)
                {
                    objFormDS.object(fieldNum(TaxInformationCustTable_IN, AZ_RegistrationNumber)).mandatory(true);
                    objFormDS.object(fieldNum(TaxInformationCustTable_IN, AZ_RegistrationNumber)).allowEdit(true);
                    objFormDS.object(fieldNum(TaxInformationCustTable_IN, AZ_UnauthorizedDealer)).mandatory(true);
                    objFormDS.object(fieldNum(TaxInformationCustTable_IN, AZ_UnauthorizedDealer)).allowEdit(true);
                }
                else if (this.AZ_RegistrationNumber)
                {
                    objFormDS.object(fieldNum(TaxInformationCustTable_IN, AZ_UnauthorizedDealer)).mandatory(false);
                    objFormDS.object(fieldNum(TaxInformationCustTable_IN, AZ_UnauthorizedDealer)).allowEdit(false);
                    this.AZ_UnauthorizedDealer = NoYes::No;
                }
            }

        break;
    }
    // Azelis <--
}


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at

    That's because you are not using the datasource reference of the form being used, but rather from the form created in code. By the way, the code to create a form in this method doesn't make sense.

    It is possible to get a reference to the datasource object using the common.dataSource() method, if the table buffer is being used in form as a datasource of course. You can check that with common.isFormDataSource().

  • Suggested answer
    Karthickks Profile Picture
    100 on at

    Hi,

    Why can't you write in  form level methods?

  • Community Member Profile Picture
    on at

    Hi Anton,

    Thanks a lot for your response. Can you please let me know how can I use common.datasource() or common.isFormDataSource in my code to reference the form's data source. Please ?

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Hi ax_dizzyness,

    That's a really strange code, you don't need to create your own form sure. It should be something like:

    public void modifiedFieldValue(FieldName _fieldName, int _arrayIndex = 1)
    {
        // Azelis -->
        #isoCountryRegionCodes
        TaxInformationCustTable_IN  taxInfoCustTable;
        boolean                     boolActive;
        FormDataSource              fds;
    
        switch(_fieldName)
        {
            case fieldStr(TaxInformationCustTable_IN, AZ_UnauthorizedDealer):
    
                if (SysCountryRegionCode::isLegalEntityInCountryRegion([#isoIN]))
                {
                    if (this.isFormDataSource())
                    {
                        fds = this.dataSource();
                    
                        if (this.AZ_UnauthorizedDealer == NoYes::Yes)
                        {
                            fds.object(fieldNum(TaxInformationCustTable_IN, AZ_RegistrationNumber)).mandatory(false);
                            fds.object(fieldNum(TaxInformationCustTable_IN, AZ_RegistrationNumber)).allowEdit(false);
                            this.AZ_RegistrationNumber = '';
                        }
                        else if (this.AZ_UnauthorizedDealer == NoYes::No)
                        {
                            fds.object(fieldNum(TaxInformationCustTable_IN, AZ_RegistrationNumber)).mandatory(true);
                            fds.object(fieldNum(TaxInformationCustTable_IN, AZ_UnauthorizedDealer)).allowEdit(false);
                            fds.object(fieldNum(TaxInformationCustTable_IN, AZ_RegistrationNumber)).allowEdit(false);
                        }
                    }
                }
    
            break;
        }
    }


  • Community Member Profile Picture
    on at

    Hi Ivegen,

    Thank you so much for your response.

    I ll try the way you have suggested and let you know shortly.

    That you once again

  • Community Member Profile Picture
    on at

    Hi Ivegen,

    thanks a lot for you reply. you answer works like a charm.

    can i use the same logic if supposed I call form's datasources from custom classes ?

    Please let me know

    once again thank you so much.

  • Mea_ Profile Picture
    60,284 on at

    If you have a cursor in this case is "this" then you can check if it is a form data source using isFormDatasource and then grab datasource in any class, table and form.  

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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans