Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Unanswered

How can I hide tabs based on selection of 2 fields?

Posted on by 65

Hello,

I have a form and many tabs in it. In the general tab, I select primary asset type( reference group I mean lookup) and asset type(enum). I need to hide and display some of the tabs based on the selection of both primary asset types and asset types. I wrote a code for this (I use OnModified event to select Primary asset Type) and I can hide or display tabs based on the selection of primary asset type but I am not sure how do I add those code selections of asset types, too.

If someone can help me with this I would be really appreciated it.

[FormDataFieldEventHandler(formDataFieldStr(EntAssetObjectTable, FixedAsset, PrimaryAssetType), FormDataFieldEventType::Modified)]
    public static void PrimaryAssetType_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
    {
        FormDataSource dataSource = sender.datasource();
        EntAssetObjectTableFormDataFieldEvent::UpdateTab(dataSource);
    }

    /// 
    ///
    /// 
    /// 
    /// 
    [FormDataSourceEventHandler(formDataSourceStr(EntAssetObjectTable, FixedAsset), FormDataSourceEventType::Activated)]
    public static void FixedAsset_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        EntAssetObjectTableFormDataFieldEvent::UpdateTab(sender);
    }

    public static void UpdateTab(FormDataSource sender)
    {
        
        FixedAsset fixedAsset = sender.cursor();
        FormRun formRun = sender.formRun() as FormRun;


        FormControl le = formRun.design().controlName(formControlStr(EntAssetObjectTable, TabA));
        FormControl pg = formRun.design().controlName(formControlStr(EntAssetObjectTable, TabB));
        FormControl c = formRun.design().controlName(formControlStr(EntAssetObjectTable, TabC));
        FormControl d = formRun.design().controlName(formControlStr(EntAssetObjectTable, TabD));
        FormControl e = formRun.design().controlName(formControlStr(EntAssetObjectTable, TabE));

        a.visible(false);
        e.visible(false);
        c.visible(false);
        b.visible(false);
        e.visible(false);

        var primary = PrimaryAssetType_WM::findByRecId(fixedAsset.PrimaryAssetType);
        var type = FixedNonFixedSelectionBaseEnum_WM::NonFixedAssets;
            switch(primary.Code)
            {
                case 'x':
                    a.visible(true);
                    break;

                case 'y':
                    b.visible(true);
                    break;

                case 'z':
                    c.visible(true);
                    d.visible(true);
                    break;

                case 't':
                    e.visible(true);
                    a.visible(true);
                    break;

            }

Thanks, regards...

  • ergun sahin Profile Picture
    ergun sahin 8,812 Super User on at
    RE: How can I hide tabs based on selection of 2 fields?

    I did not fully understand the problem. Let's talk about single-field control first;

    I see that you use both OnActivated and OnModified in the code. Actually you have to write in OnActivated, not OnModified. Why did you use OnModified? OnActivated wasn't enough?

    If we talk for two fields, instead of filling the enable value as true/false directly, you should keep it in a boolean variable.

    You may then concatenate with the value from the enum

    Or you can create branchs with enum as a second condition inside the switch case.

    Since we do not know the relationship between the two data, it is difficult to say for sure. If you show your expectations with examples, we can help you combine the two terms.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,420 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,672 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans