Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

How to enable/disable dynamically added data source

(0) ShareShare
ReportReport
Posted on by 2,015

Hi Techies,

I want to enable/disable a dynamically added data source in a code at a particular condition. If the values of the fields(FromDate and ToDate) are blank then it should be disabled else it should enable. I tried doing this ->qbds.childDataSourceNo(2).enabled(true); but it is showing error - 'Query does not contain 2 datasources'

Below is my code

QueryBuildDataSource qbds = ds.addDataSource(tableNum(LedgerJournalTrans));
qbds.relations(true);
qbds.joinMode(JoinMode::ExistsJoin);
qbds.addRange(fieldNum(LedgerJournalTrans,TransDate)).
value(strFmt('%1..%2',formRun.parmFromDate(),formRun.parmTodate()));


Can anyone help me here,

Any response is appreciated!

Thanks

*This post is locked for comments

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: How to enable/disable dynamically added data source

    One solution would be keeping your joined data source, but passing dateNull() and maxDate() as the date range.

    In your code you have introduced a new QueryBuildDataSource which has one data source table.

    Therefore qbds.childDataSourceNo(2).enabled(true) can't work, can it? Or is qdbs referring to something else in the place where you are using it?

  • Reliable Profile Picture
    Reliable 2,015 on at
    RE: How to enable/disable dynamically added data source

    I want to show data according to the dates selected, in current situation- if i select these dates on form, the code is adding this data source and showing me data as required, now if I remove the dates then it should display all records on form without considering this date filter, in my condition the added data source is remaining in a query and showing previous data.

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans