Have you ever noticed that when you explicitly call DataSourceName_ds.executeQuery() it reinstantiates the queryRun of the form and thus removes all the query filters (not ranges!). This article explains ho to preserve form query filter throught Extension after explicit ExecuteQuery call on a data source : https://community.dynamics.com/365/financeandoperations/b/elandaxdynamicsaxupgradesanddevelopment/posts/preserve-form-query-filters-after-explicit-executequery-call-on-a-data-source-helper-class-included
Category: Data source
AX / D365FO – Get datasource from a Form extension class
At Form Level [ExtensionOf(formStr(SalesTable))] final class KSSalesTableFrm_Extension { public int active() { FormRun formRun = this as FormRun; //get any datasource from the base form FormDataSource salesLine_ds = formRun.datasource(FormDatasourceStr(SalesTable,SalesLine)); SalesLine salesLine = salesLine_ds.Cursor(); //get any formcontrol from the base form FormControl itemName= formRun.design().ControlName(FormControlStr(SalesTable, itemName)); //business Logic return next active(); } } At FormDataSource level [ExtensionOf(formDatasourceStr(SalesTable, … Continue reading AX / D365FO – Get datasource from a Form extension class
AX / D365FO – Form Field allow edit based on conditon
If you want to allow edit only some fields on the form grid control this is an example that shows hot to reach this goal. 1. Create a Form method as below public void setFieldAccess() { if(XXXX == YYY) { FrmDataSource_ds.object(fieldNum(FrmDataSource,LineNum)).allowEdit(false); FrmDataSource_ds.object(fieldNum(FrmDataSource,Field2)).allowEdit(false); } } 2. Call the above method from the form Data source Active … Continue reading AX / D365FO – Form Field allow edit based on conditon
AX / D365FO – How to call an Action Menu Item in a Form event handler
In this example I want to call a menu item every time a Data source record is deleted [FormDataSourceEventHandler(formDataSourceStr(ProjSalesItemReq, SalesLine), FormDataSourceEventType::Deleted)] public static void SalesLine_OnDeleted(FormDataSource sender, FormDataSourceEventArgs e) { Args args = new Args(); FormRun formRun = sender.formRun(); //Get FormRun FormDataSource salesLine_ds = formRun.dataSource(formDataSourceStr(SalesLine, SalesLine)) as FormDataSource; //Get DataSource SalesLine salesLine = salesLine_ds.cursor(); //Get DataSource … Continue reading AX / D365FO – How to call an Action Menu Item in a Form event handler
AX / D365FO – How to refresh form in x++
You can just set property "Auto refresh data" of a button to Yes or alternatively via x++ you can use this code datasource.refresh(); datasource.research(true);
AX – D365FO – Change data in calling datasource
formDataSource formDataSource; formRun formRun; salesTable salesTable; int i; // Change data in calling datasource if(element.args() && element.args().caller() && element.args().caller().handle() == className2Id('formRun')) { formRun = element.args().caller(); for (i = 0; i <= formRun.dataSourceCount(); i++) { formDataSource = formRun.datasource(i); if (formDataSource && formDataSource.table() == tablenum(salesTable)) // Search for specific table { salesTable = formDataSource.cursor(); break; } } … Continue reading AX – D365FO – Change data in calling datasource
AX – D365FO – Refresh grid data with Command Button
To refresh grid data of a Form grid just create a Command Button and set Command Property to Refresh Obviously the button must be created under a Group button object and this under an Action Pane which contains the data source that must be refreshed.
AX – D365FO – Detect selected line (row) changed in FormGridControl
To detect selected line just use form data sources. Override active() method of the date source - it's executed when a user switches to another record. The active record is in the automatic variable with same name as the data source. Here is an example public int active() { int ret; ret = super(); if (ret) { … Continue reading AX – D365FO – Detect selected line (row) changed in FormGridControl
AX – D365FO – Mark a form grid record with checkbox
This example mark all records of a form grid record looping throught the data source public void selectall(boolean _select) { CompanyInfo localCompanyInfo; localCompanyInfo = companyInfo_ds.getFirst(); while(localCompanyInfo) { this.findRecord(localCompanyInfo); this.mark(_select); localCompanyInfo = companyInfo_ds.getNext(); } }
AX – D365FO – Loop through record from data source
/////////////////////////////////////////////// Using a while loop SalesLine localSalesLine; localSalesLine = salesLine_ds.getFirst(true) as SalesLine; if (localSalesLine) { while (localSalesLine) { //Do your thing localSalesLine = salesLine_ds.getNext() as SalesLine; } } /////////////////////////////////////////////// Using a for loop SalesLine localSalesLine; for (localSalesLine = salesLine_ds.getFirst(true) ? salesLine_ds.getFirst(true) : salesLine_ds.cursor(); localSalesLine; localSalesLine = salesLine_ds.getNext()) { //Do your thing }