Posts

Showing posts from February, 2024

D365F&O - X++ - Insert records in database using recordInsertList

public void insertCustRecords(CustStatementDirTmp _custStatementDirTmp, Query _userQueryPacked) {         CustTable               cust;         QueryBuildDataSource    dataSource;         QueryRun                partyRun;         Query                   Query = new Query(_userQueryPacked);         RecordInsertList        recordInsertList;             partyQuery.allowCrossCompany(false);             dataSource = partyQuery.dataSourceTable(tableNum(CustTable));             partyRun = new QueryRun(partyQuery);             recordInsertList = new RecordInsertList(_custStatementDirTmp.TableId, false, false, false, false, true, _c...

D365F&O - X++ - Buf2Buf() vs Data() method vs assignment opertaor for one table buffer assignment to other

Assigning one table record to another table record, there are three ways this can be done: 1- Assignment operator  table1 = table2; In this case, shallow copy of table record is assigned to second table record, which means instead of creating a copy, it points to the same table record. 2- Table.data() method table2.data(table1); Generally we use table.data() method for replicating a table record, instead of passing each  field one by one. However, table.data() method also copies the system fields, and if we are inserting data across companies , we cannot use table.data() method. 3- Buf2Buf() method Buf2Buf(fromTable, toTable); If we don't want to copy system fields, we can use Buf2Buf() method. Also, for intercompany insert of data , we should use Buf2Buf() method with changeCompany() method().

D365F&O - X++ - Try and Catch block in x++ code

public class SalesOrderRefund {     public void process()     {         try         {             // your logic         }         catch ( Exception ::Error)         {             Microsoft.Dynamics.Ax.Xpp.ErrorException ex =                               new Microsoft.Dynamics.Ax.Xpp.ErrorException();             throw error(ex.Message);         }     } }

D365F&O - X++ - Get datasources in datasource extension on form

[ExtensionOf(formdatasourcestr(VendPaymMode,CustomTable))] final class MJ_VendPaymMode_MJVendPaymModeTable_Extension {     public void write()     {         //Get the datasource for which we are writing extension on form         CustomTable customTable = this.cursor();           //Get another datasource on form         VendPaymModeTable VendPaymModeTable = this.formRun().dataSource(                     formdatasourcestr(VendPaymMode, VendPaymModeTable)).cursor();         customTable.VendPaymModeRecId = VendPaymModeTable.RecId;         next write();     } }

D365F&O - X++ - Best Practice Warning BP Rule: The parameter 'sender' is not used.

class SalesOrderEventhandlers {         /// <summary>     /// your summary here     /// </summary>     /// <param name="sender">sender</param>     /// <param name="e">DataEventArgs instance</param>     [DataEventHandler(tableStr(MJItemOutputGSIDWStaging), DataEventType::Inserted),         SuppressBPWarning( "BPParameterNotUsed" , "Parameter required by the event interface" )]     public static void SalesOrder_onInserted(Common sender, DataEventArgs e)     {         // your logic here     } }