Delegates in Microsoft Dynamics D365 are the methods for accessing elements in higher model from a lower model & solving dependencies among models.Delegates serves as a contract between delegate instance & delegate handler.
For example
I have a scenario.I have 2 models i.e. Model A & Model B.In Model B i passed the reference of model A but vice-versa is not possible.It means i can call objects of model A in model B.But i cannot call objects of Model B in Model A.Here we can use delegates for accessing Model B values in Model A.
Sample Code & Explanation
Create a Model A & create a delegate.Delegate method should be empty and void type.[code language = “cpp”]
public class MyClassInModelA
{
delegate void myDelegate(EventHandlerResult _result)
{
}
}
[/code]
Create a Model B & passed the reference of Model B using “Update Model Parameters”.It means i can call objects of model A.
Create a class in Model B & write a delegate handler.[code language = “cpp”]
class MyClassInModelB
{
[SubscribesTo(classStr(MyClassInModelA), delegateStr(MyClassInModelA, myDelegate))]
public static void myDelegateHandler(EventHandlerResult _result)
{
str ret = “Hi!This is Model B Values”;
_result.result(ret);
}
}
[/code]
Call the subscription of delegate in Model A & access the values of Model B in Model A.In this way, i am calling Values of Model B in Model A without passing the reference of Model B in Model A.[code language = “cpp”]
public class MyClassInModelA
{
delegate void myDelegate(EventHandlerResult _result)
{
}
public static client server void main(Args args)
{
MyClassInModelA myClassInModelA = new MyClassInModelA();
MyClassInModelA.myMethod();
}
public void myMethod()
{
EventHandlerResult result = new EventHandlerResult();
this.myDelegate(result);
str common = result.result();
info(common);
}
}
[/code]
The purpose is to demonstrate the use of SQL IN operator in X++.
Limitation
The use of IN operator in X++ is only applicable for fields of data type ENUM.
Sample Code
[code language = “cpp”]
SalesTable salesTable;
container con = [SalesType::Sales, SalesType::ReturnItem, SalesType::Subscription];
while select * from salesTable
where salesTable.SalesType in con
{
Info(salesTable.SalesId);
}
[/code]
You can modify below sample code as per your need.This is just a prototype.
[code language = “cpp”]
SrsReportRunController reportRunController = new SrsReportRunController();
dataContract = new AcxInvoiceDataContract();
reportRunController.parmReportName(ssrsReportStr(AcxInvoiceReport,dgsCredit));
reportRunController.parmDialogCaption(“Print CREDIT NOTE”);
args.menuItemType(MenuItemType::Output);
args.menuItemName(identifierStr(AcxCreditReport));
reportRunController.parmArgs(args);
reportRunController.parmLoadFromSysLastValue(false);
reportRunController.parmShowDialog(false);
dataContract.parmInvoiceId(custInvoiceJourLocal.InvoiceId);
dataContract.parmCopyName(“Original for Recipient”);
reportRunController.parmReportContract().parmRdpContract(dataContract);
reportRunController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::Printer);
// here is i am selecting only first active printer but you can make it configurable
select firstonly netPrinters
where netPrinters.PrinterName == printname
&& netPrinters.Active == NoYesCombo::Yes ;
//here i am passing printer name
reportRunController.parmReportContract().parmPrintSettings().printerName(netPrinters.PrinterName);
reportRunController.parmExecutionMode((SysOperationExecutionMode::Synchronous));
reportRunController.startOperation();
[/code]
Some new custom fields are created on extension of table InventTable.Customer wants to see these custom fields in the item lookup of sales order, transfer order & inventory journals etc.
Steps
Create the extension of table InventTable and add your custom fields.
Create the extension of view InventItemIdLookupSimpleView and add your custom fields.
Create the extension of form InventItemIdLookupSimple and add your custom fields in the GRID of the form.
Create the extension of class InventItemIdLookupSimple
[code language = “cpp”]
[ExtensionOf(classstr(InventItemIdLookupSimple))]
final class AcxInventItemIdLookup_Extension
{
protected void addStandardFields()
{
List lookupFields1 = lookupFields;
next addStandardFields() ;
lookupFields1.addEnd((fieldNum(InventItemIdLookupSimpleView, AcxItemCode)));// added my custom field
lookupFields = lookupFields1;
}
}
[/code]
There are many data entities available in dynamics D365 Finance & Operations(Example: EcoResReleasedProductV2Entity, InventWarehouseEntity).Requirement of updating or inserting values in custom field of standard table by extending standard or base Data Entity are very common.The purpose of this post is Adding a new custom Field In Standard or Base Data Entity (Example: EcoResReleasedProductV2Entity, InventWarehouseEntity).
Requirement
A new custom field needs to be created on InventLocation Table.The same field has to be added in base or standard data entity InventWarehouseEntity.User will be able to update the value of custom field value in InventLocationTable by using base or standard data entity InventWarehouseEntity.
Steps
Create a new field in extension of table InventLocation.
Add the new custom field created in Step 1 into the extension of data entity InventWarehouseEntity.
Add the new custom field created in Step 1 into the extension of staging table data entity InventWarehouseEntity.
Some X++ hotfixes related to model “DemoDataSuite” belongs to your one-box development machine only.It means you cannot deploy it on UAT or on production environment else you will get below error related to applicationfoundationformadaptor dependency
The running command stopped because the preference variable “ErrorActionPreference” or common parameter is set to Stop: Unable to resolve dependency ‘dynamicsax-applicationfoundationformadaptor’.
Solution
To exclude package “DemoDataSuite” or any other model from VSTS Or DevOps build output you can set the parameter or variable PackagingExclusions before queuing the build.Once the build will complete, deployable packages or artifacts will not contain excluded models.
Microsoft Dynamics AX, Microsoft Dynamics 365 for Finance and Operations, D365 FO, Retail, SQL, Microsoft Power Apps, Microsoft Power BI, Microsoft Azure, Logic Apps, Microsoft Flow, Microsoft power automate, Microsoft Power Platform,.Net, X++, C#, Power BI DAX, Data Warehousing, Microsoft Analysis Services, SQL Server Reporting Services