Posts

Showing posts from November, 2023

D365F&O - X++ - set display method from table extension in form control

Image
 1- Right click on the table and click "create extension" and write your display method. [ExtensionOf(tableStr(CustTrans))] final class CustTransTable_Extension {     public display CustGroupId getCustGroup()     {         return CustTable::find(this.AccountNum).CustGroup;     } } 2- Go to the control where you want to set the display method set display method as below

D365F&O - X++ - Best Practice Warning BP Rule: [BPErrorUnknownLabel]: Path:

To resolve the following error:  Path: [dynamics://Table/SalesTable/Field2]:Unknown label ‘@ZILabel:NewLabel’. Legacy labels (such as the label id @SYS12345) are case insensitive and modern labels (such as ‘MyLabelId’ in @MyLabelFile:MyLabelId) are case sensitive. Use upper casing when referring to legacy labels and exact casing for modern labels.  use  literalStr()  before the custom label. info(literalStr(" @ZILabel:NewLabel " ) ) ;

D365F&O - X++ - Get form control in coc method in form extension

[ExtensionOf(formControlStr(SalesUpdateRemain, ButtonCancelLine))] final class SalesUpdateRemainButtonCancel_Extension {     void clicked()     {         next clicked();         #define.SalesPhysical('remainSalesPhysical')         FormControl formButtonControl = any2Object(this) as FormControl;         FormRealControl remainSalesPhysicalControl = formButtonControl.formRun(). control(formButtonControl.formRun().controlId(             (formcontrolstr(SalesUpdateRemain, remainSalesPhysical )) ));                 remainSalesPhysicalControl.realValue(50 0 );     } }

D365F&O - X++ - Best Practice Warning [BPUnusedStrFmtArgument]:The placeholder ‘%1’ to strFmt is not used in the format string.

 T o remove the BP warning add  literalStr()  for label string validation in your code where you have used %1 in your label string. error( strfmt( literalStr( "@MyLabel:LabelCust" ), CustTable.InvoiceId) ) ;

D365F&O - X++ - Get datasource in modified method COC in form control extension

[ExtensionOf(formControlStr(CustFreeInvoice, OrderAccount))] final class CustFreeInvoiceOrderAccount_Extension {     public boolean modified()     {         Boolean ret = next modified();         FormControl formControl = any2Object(this) as FormControl;         FormDataSource custInvoiceTable_ds =                formControl.formRun().dataSource(tableStr(CustInvoiceTable));         custInvoiceTable custInvoiceTable = custInvoiceTable_ds.cursor();                 if (CustInvoiceTable.RecId == 0 )         {             ret = true ;         }         custInvoiceTable_ds.research(true);         return ret;     } }  

D365F&O - X++ - create modified method coc of form control in form extension

 1- Right click on form and click "create extension". [ExtensionOf(formControlStr(CustFreeInvoice, OrderAccount))] final class CustFreeInvoiceOrderAccount_Extension {     public boolean modified()     {         Boolean ret = next modified();                   FormDataSource custInvoiceTable_ds = this.formRun().dataSource(tableStr(CustInvoiceTable));         custInvoiceTable custInvoiceTable = custInvoiceTable_ds.cursor();                if (CustInvoiceTable.RecId == 0 )         {             CustInvoiceTable.write();         }         custInvoiceTable_ds.research(true);         return ret;     } }

D365F&O - X++ - Get formdatasource in init method in form extension

 public void init() {     next init();          FormDataSource SalesTable_ds = this.dataSource(formDataSourceStr(        CustTrans, SalesTable));     SalesTable_ds.queryBuildDataSource().clearLinks();     SalesTable_ds.queryBuildDataSource().addLink(fieldNum(CustInvoiceJour, SalesId),     fieldNum(SalesTable, SalesId)); }

D365F&O - X++ - Create init method COC in form datasource Extension in x++

1- Create a new class and name it "CustParameters_SalesParameters_Extension". 2- Override init method. [ExtensionOf(formDataSourceStr(CustParameters, SalesParameters))] final class CustParameters_SalesParameters_Extension {     public void init()     {         next init();           // get current record         SalesParameters SalesParams = this.cursor();         // Your logic here     } }

D365F&O - X++ - Get formbuttoncontrol and multiple datasource records in onclicked eventhandler

[FormControlEventHandler(formControlStr(CostSheetCalculationFactor, MassInventPriceCalcFactorActivateButton), FormControlEventType::Clicked)] public static void MassInventPriceCalcFactorActivateButton_OnClicked( FormControl sender, FormControlEventArgs e) {     #define.BUTTONNAME('MassInventPriceCalcFactorActivateButton')     CostSheetCalculationFactor              costSheetCalculationFactorLocal;     MultiSelectionHelper                    selectionHelper =                                                        MultiSelectionHelper::construct();     boolean                                 enableActivateButton = true; ...

D365F&O - X++ - get form datasource in validatewrite in form event handlers

[FormDataSourceEventHandler(formDataSourceStr(AssetTable, AssetTable), FormDataSourceEventType::ValidatingWrite)] public static void AssetTable_OnValidatingWrite(FormDataSource sender, FormDataSourceEventArgs e) {     FormDataSource  formDatasource;     AssetTable AssetTable;     FormRun formRun = sender.formRun();     FormStringControl AssetId = formRun.design().controlName(formcontrolstr(AssetTable,                         Identification_AssetId ));     str AssetIdValue = AssetId.valueStr();     MJAssetTable = sender.cursor();     if ( ! AssetTable.AssetId)     {         AssetTable.AssetId =AssetIdValue;     } }

D365F&O - X++ - create button onclicked eventhandler on form extension

[FormControlEventHandler(formControlStr(CostingVersion, CalcInMass), FormControlEventType::Clicked)] public static void CalcInMass_OnClicked(FormControl sender, FormControlEventArgs e) {     FormDataSource  formDatasource;     BOMCalcJob_All  BOMCalcJob_All;     CostingVersion      CostingVersion;     formDatasource = sender.formRun().dataSource( 1 );     CostingVersion = formDatasource.cursor();     BOMCalcJob_All = BOMCalcJob_All::newAll(CostingVersion);         if (BOMCalcJob_All.prompt())     {         BOMCalcJob_All.modifyQuery();         BOMCalcJob_All.run();     } }

D365F&O - X++ - Create Service class for consuming 3rd party API using Basic Authentication method

 We are going to create a service that sends data in following format: {    "amount"  : {      "currency"  :  "AED" ,      "value"  : 5 000   },    "CustomerName"  :  "Test Customer" ,    "SalesOrderID"  :  "SO-0001" } 1- First of all, we are going to create request contract to send the above JSON to the postman. 2- create a class for request amount since it has 2 values that are combined and make one amount. [DataContract] class SalesOrderAmountDetailsContract {     Amount lineAmount;     CurrencyCode currencyCode;     /// <summary>     /// Line Amount parameter     /// </summary>     /// <param name = "_lineAmount">lineAmount</param>     /// <returns>lineAmount</returns>     [DataMember( 'value' )]     public Amount parmlin...

D365F&O - X++ - Create Batch job using SysOperationServiceBase in X++

 1- Create Contract class if you want to create any parameters. [DataContractAttribute] class SysOperationsBatchContract {     TransDate asofDate;     [DataMember,     SysOperationLabel(literalStr( "As of Date" )),     SysOperationHelpText(literalStr( "Show records As of Date." )),     SysOperationDisplayOrder( '1' )]     public TrandDate parmAsOfDate( TrandDate _asofDate = asofDate)     {         asofDate = _asofDate;         return asofDate;     } } 2- Create new Controller class. public class SalesOrderRefundBatchController extends SysOperationServiceController {     /// <summary>     /// Default class contsructor     /// </summary>     protected void new()     {         super (classStr(SalesOrderRefundBatchService),                ...

D365F&O - X++ - Create and post Customer payment Journal using X++ code.

 1- Create a new class  CreatePaymentJournal. class CreatePaymentJournal {     public void createPaymentJournal()     {         System . Exception                    exception;         LedgerJournalTrans                  journalTrans;         Ledgerjournalname                   ledgerjournalname;         NumberSeq                           numberSeq;         LedgerJournalTable                  journalTable;         MCROrderParameters                  Parameters = MCROrderParameters :: find();         DimensionAttributeVal...

D365F&O - X++ - Change form control value based on the caller form in init extension method

 1- Right click on your form and click on Create code extension . [ExtensionOf(formStr(LedgerJournalTable))] final class LedgerJournalTableForm_Extension {     void init()     {         next  init();                 if  ( this .args().callerName())         {             if ( this .args().callerName() == formStr(OrderRefundListPage))             {                 allOpenPostedField.selection(AllOpenPosted :: All);             }         }     } }

D365F&O - X++ - check caller form menu item name

 1- Override init method of your form and write the below code. void init() {     info ( this .args().callerName()); }

D365F&O - X++ - Filter the form records based on the caller form in excuteQuery method

 1- Open the form designer. 2- Go to datasource, expand and right click on methods. 3-  select override  executeQuery  method. public void executeQuery() {     // Get the calling  form record     OrderRefundTable orderRefund = element.args().record();     QueryBuildDataSource  queryBuildDataSource;                 queryBuildDataSource = this .query().dataSourceTable(tablenum(OrderRefundTable));     queryBuildDataSource.clearRanges();      // Add range to your current form datasource     queryBuildDataSource.addRange(fieldnum(OrderRefundTable, SalesId)).value           (queryValue(orderRefund.SalesId));     super ();     }

D365F&O - X++ - Get multiple datasource selected record from Listpage/Grid

1- Open the form designer. 2- Go to datasource whose records you want to select. 3- Expand and right click on methods, select override active method. public int active() {     FormDataSource SalesTable_ds;     SalesTable      SalesTable;                 ret = super ();     SalesTable_ds = this .formRun().dataSource( 'SalesTable' );     // Get first selected record     SalesTable = SalesTable_ds.getFirst( 1 );     while (SalesTable)     {             // Assign next selected record         SalesTable = SalesTable_ds.getNext();     } }

D365FO – X++ – create a simple dialog box in Dynamics 365F&O

DialogButton  diagBut; // Message of the dialog box str strMessage = "Do you want to proceed with the sales refund processing?" ; // Title of the dialog box str strTitle = "Process Refund Orders" ; diagBut = Box :: yesNo(strMessage, DialogButton :: No,  strTitle); if (diagBut == DialogButton :: Yes) {     // Your logic if Yes button is clicked } else {     // Your logic if No button is clicked }

D365F&O - X++ - How to Enable/Disable button on form based on a condition in D365F&O using Event handlers.

Image
1- Create a new class SalesOrderFormEventHandlers . 2- Go to SalesTable form. 3- Expand SalesTable datasource. 4- Expand Events , right click on OnActivated and click on Copy event handler method. 5- Paste the code in your  SalesOrderFormEventHandlers class. 6- Save and build your project. class SalesOrderFormEventHandlers {     /// <summary>     /// Enable or disable Refund button     /// </summary>     /// <param name="sender"></param>     /// <param name="e"></param>             [FormEventHandler(formStr(SalesTable), FormEventType :: Activated)]     public static void SalesTable_OnActivated(xFormRun sender, FormEventArgs e)     {           // Button control name in your form design         #define.BUTTONNAME( 'JWRefundButton' )         FormDataSource form_ds = sender.dat...

Jump ref method

public void jumpRef ()     {         super ();         Args args = new Args ();         MenuFunction menuFunction ;         menuFunction = new MenuFunction ( MenuItemDisplayStr (ItemGroupItems),                  MenuItemType :: Display);         IaxItemGroup item ;         args . record (item);         args . caller (element);         menuFunction . run (args);         }