Posts

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

D365FO - X++ - Generate CAR (Customized Analysis Report) report of custom model

Image
1- Open command prompt by clicking on "Run as Administrator". 2- Select the drive where your model and package exist in command prompt. My custom model is in K: folder. W rite the following command.   3- Copy the following command and run. K:\AosService\PackagesLocalDirectory\bin\xppbp.exe -metadata=K:\AosService\PackagesLocalDirectory -all -model=yourModel -xmlLog=K:\BPCheckLogcd.xml -module=yourModel -car=K:\CARReport 4- After successful completion, the CAR report will be saved to the given path

D365F&O - X++ - Set contract parameter value in controller class of SysOperationServiceBase framework

/// <summary> /// A class entry point /// </summary> /// <param name = "_args">An instance of <c>Args</c> which /// contains calling arguments</param> public static void main(Args _args) {     str caption;     ItemExportController   controller;     controller = ItemExportController::construct(); // get data contract object     ItemExportContract contract = controller.getDataContractObject();      // set data parameter value     contract.parmitemExportSystem(_args.parmEnum());             controller.parmArgs(_args);     controller.startOperation(); }