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
Category: Data source
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 }
AX – D365FO – Get source record from a caller object
In this example I'll show how to obtain the source record from a caller object. Suppose you have a form A that calls form B. In Form B you want to know what is the data source of the Form A and if it's a VendTable you want to retrieve the AccountNum field VendTable vendTableLocal; … Continue reading AX – D365FO – Get source record from a caller object
AX – D365FO – Get DataSource name of a caller object
Suppose you have a form A that calls form B. In Form B you want to know what is the data source of the Form A and do something..... This is the code to obtain the data source name of a caller object (such as Form, menu item, etc..). args.record().dataSource().Name();