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 – 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 – 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 – 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 }