Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

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

Posted on by Microsoft Employee

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 <--
}


  • Mea_ Profile Picture
    Mea_ 60,274 on at
    RE: How to make a form datasource fields mandatory from a table method

    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.  

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to make a form datasource fields mandatory from a table method

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to make a form datasource fields mandatory from a table method

    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

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,274 on at
    RE: How to make a form datasource fields mandatory from a table method

    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
    Community Member Microsoft Employee on at
    RE: How to make a form datasource fields mandatory from a table method

    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
    Karthickks Profile Picture
    Karthickks 100 on at
    RE: How to make a form datasource fields mandatory from a table method

    Hi,

    Why can't you write in  form level methods?

  • Suggested answer
    Anton Venter Profile Picture
    Anton Venter 5,028 Super User on at
    RE: How to make a form datasource fields mandatory from a table method

    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().

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,663 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 224,741 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans