Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

How to set condition on datasource level for fields

Posted on by 43

Dear community i am looking for answer that how i can set condition on datasource level in AX2012 .
Senario is something like this
i have 5 record lines

Example: We have three fields ID , Name, City
i want to set condition like this

if(city == 'abc')
{
SHOW NAME AND CITY COLUMN IN GRID
}
ELSE
{
SHOW ONLY ID IN GRID
}

How i can set this condition by using datasource level fields ?

  • Wajahat wasti Profile Picture
    Wajahat wasti 43 on at
    RE: How to set condition on datasource level for fields

    I am working for purchase order lines grid .When we will open PO data will fetch on grid .

    Basically i want to reduce process time because display methods consume more time to access data from db .. This can be possible by using query and view then drop view as form source on form drop field from datasource to grid but having problem while implementing above condition .

  • Suggested answer
    Komi Siabi Profile Picture
    Komi Siabi 12,377 Super User on at
    RE: How to set condition on datasource level for fields

    the field on the datasource would have to be used on the form design if I am not mistaken?

    Maybe you should explain at what point exactly you want the condition.

    Is it on immediately you open the form ?

    When user select data on any of the field ?

  • Wajahat wasti Profile Picture
    Wajahat wasti 43 on at
    RE: How to set condition on datasource level for fields

    But my question is about how i can set condition by datasource field ..your answer is for condition by grid column .

    thanks

  • Suggested answer
    Komi Siabi Profile Picture
    Komi Siabi 12,377 Super User on at
    RE: How to set condition on datasource level for fields

    Did you see the if statement in my code ?

    if(MainGrid_City.valueStr() == "Abc") /// Here is the condition

    You should also override the modifiedField method the City field and put the logic

  • Wajahat wasti Profile Picture
    Wajahat wasti 43 on at
    RE: How to set condition on datasource level for fields

    Thanks Komi

    your answer resolve 50% my problem to set condition but another half is

    showing data from datasource with in condition

    i want to show values on behalf of condition  

  • Suggested answer
    Komi Siabi Profile Picture
    Komi Siabi 12,377 Super User on at
    RE: How to set condition on datasource level for fields

    Hello, 

    1. 

    Firstly, you need to set the auto declaration property to Yes for all the fields on the grid : Id, Name, City.

    2. You might want to Hide these 3 fields on init of the form by doing this.

        public void init()
        {
            super();
            if(MainGrid_City.valueStr() == "Abc")
            {
                MainGrid_id.visible(false);
                MainGrid_name.visible(true);
                MainGrid_City.visible(true);
            }
            else
            {
                MainGrid_id.visible(true);
                MainGrid_name.visible(false);
                MainGrid_City.visible(false);
            }
            
        }

    MainGrid is the name of the Grid on your form.

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... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans