Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
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,692 Most Valuable Professional 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,692 Most Valuable Professional 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,692 Most Valuable Professional 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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans