Hey
I got one Table and I want to put a filter on it (on action).
Only entries with a certain value that dont exists in the same table and another value should be shown.
This is the working MSSQL-Statement:
SELECT * FROM SYC_ERP_WorkingHourAccountOverview as t1 WHERE MonthsWOvertimeHours >= 12 AND NOT EXISTS (SELECT * FROM SYC_ERP_WorkingHourAccountOverview WHERE MonthsWOvertimeHours < 12 and t1.Worker = Worker and t1.Year = Year and t1.MONTH = Month)
And this is the AX-Code I am using (obviously wrong):
Query query = new Query(); QueryBuildDataSource ds1 = query.addDataSource(tableNum(SYC_ERP_WorkingHourAccountOverview)); ds1.addRange(fieldnum(SYC_ERP_WorkingHourAccountOverview, MonthsWOvertimeHours)).value('(MonthsWOvertimeHours > 11)'); QueryBuildDataSource ds2 = ds1.addDataSource(tableNum(SYC_ERP_WorkingHourAccountOverview)); ds2.joinMode(JoinMode::NoExistsJoin); ds2.addRange(fieldnum(SYC_ERP_WorkingHourAccountOverview, MonthsWOvertimeHours)).value('(MonthsWOvertimeHours < 12)'); ds2.addLink(fieldNum(SYC_ERP_WorkingHourAccountOverview, Worker), fieldNum(SYC_ERP_WorkingHourAccountOverview, Worker)); ds2.addLink(fieldNum(SYC_ERP_WorkingHourAccountOverview, Month), fieldNum(SYC_ERP_WorkingHourAccountOverview, Month)); ds2.addLink(fieldNum(SYC_ERP_WorkingHourAccountOverview, Year), fieldNum(SYC_ERP_WorkingHourAccountOverview, Year)); info(ds1.toString());
The result of the Query is:
SELECT * FROM SYC_ERP_WorkingHourAccountOverview(SYC_ERP_WorkingHourAccountOverview_1) WHERE (((MonthsWOvertimeHours > 11))) NOTEXISTS JOIN * FROM SYC_ERP_WorkingHourAccountOverview(SYC_ERP_WorkingHourAccountOverview_1_1) WHERE SYC_ERP_WorkingHourAccountOverview.Worker = SYC_ERP_WorkingHourAccountOverview.Worker AND SYC_ERP_WorkingHourAccountOverview.Month = SYC_ERP_WorkingHourAccountOverview.Month AND SYC_ERP_WorkingHourAccountOverview.Year = SYC_ERP_WorkingHourAccountOverview.Year AND (((MonthsWOvertimeHours < 12)))
Can anyone help me out to get my query right?
Are there good resources for learning purposes? Iam pretty new in AX.
Thank you very much.