Posts

Showing posts from 2024

X++ code to refresh the caller form in D365FO

 Below is the code snippet to refresh the caller form from class Main method. X++ code:    #Task    FormRun caller = _args.caller();    if (caller)     {           caller.task(#taskRefresh);      }

Export Data Packages using Data Management and Postman in D365FO

Image
 Steps to export data packages using data management framework and Rest API in D365FO  Step 1: Create a new data export project using DMF. This project should include the data entities which are required for the export. Step 2: Export the package using postman, To do it, Mainly we need below 3 information. {{ D365URL }} : Dynamics 365 URL DefinitionGroupId : DMF Project name packageName : Name of the export package REST API URL:  {{D365URL}} /data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.ExportToPackage Body: Response from Postman: Upon execution success, Postman will provide a  response indicating that the export has been initiated. Step 3: Check export package status using the API {{D365URL}} /data/DataManagementDefinitionGroups/Microsoft.Dynamics.DataEntities.GetExecutionSummaryStatus and the Body Response of the API call: Step 4: Download the Package. To download the exported package, run the the below API and Body. The response will provid...

X++ code to get sales order totals in D365FO

 Below is the code snippet to get sales totals of open order and invoiced sales orders Open order Sales Orders:    container displayFields = S alesTotals::displayFieldsServer (salesTable, SalesUpdate::All, "");   real totalAmountIncTax  = conpeek(displayFields, TradeTotals::posTotalAmount());   real totalAmountExcTax  = conPeek(displayFields, TradeTotals::posBalance());   real totalAmountTax     = conpeek(displayFields, TradeTotals::posTaxTotal()); Invoiced Sales Orders:  SalesQty    qty; Amount      totalAmountIncTax,totalAmountTax,totalAmountExcTax; [totalAmountIncTax,totalAmountTax,totalAmountExcTax,qty] = ANI_SalesEventHandlers::getSalesInvoiceAmountAndTax(salesTable); real totalAmountExcTax = totalAmountExcTax; real totalAmountIncTax = totalAmountIncTax; real totalAmountTax    = totalAmountTax;      /// <summary>     /// Get Invoiced Sales Order Amount, tax,...

Generate all days of a month in Excel

Image
  Formula to get Number of days in the month (B2): =DAY(EOMONTH(B1,0)) Formula to generate all the days:  =DATE(YEAR(B1),MONTH(B1),SEQUENCE(B2))

Copy attachments from sales order to production order while firming planned production order in D365FO

 In D36FO, it is common requirement to copy documents from one table to another table. Here is an example to copy documents of type "Note" from Sales order to production order during firming and Also update/delete the records in planned order if the document attachment is updated/deleted in sales order. code snippets: /// <summary> /// Extension methods for the <C>ReqTransPOMarkFirm</C> class. /// </summary> [ExtensionOf(classStr(ReqTransPOMarkFirm))] internal final class ANI_ReqTransPoMarkFirm_Extension {     protected ProdTable createProdTable(         ReqTrans    _reqTrans,         ReqPO       _reqPO,         ProdBOM     _prodBOMParent)     {         ProdTable prodTable = next createProdTable(_reqTrans,_reqPO,_prodBOMParent);         if (prodTable && prodTable.InventRefType == InventRe...

Get running Select statement from Query during runtime in D365FO

  Syntax:  info(new query(queryStr(QueryName)).toString()); Example: info(new query(queryStr(Customer)).toString());

X++ code to generate SSRS Report Attachment in D365FO

 Below is the code snippet which helps to generate SSRS report as memory stream and then can be used it to send it through mail/upload in azure. public static System.IO.Stream generateAttachment(PurchTable _purchTable)     {         PurchTable purchTable = PurchTable::find(_purchTable.PurchId);         SrsReportRunController          ssrsController = new SrsReportRunController();         ANI_PurchPurchaseOrderContract      Contract = new ANI_PurchPurchaseOrderContract();//contract class         System.Byte[]    reportBytes = new System.Byte[0]();         SRSProxy    srsProxy;         SRSReportRunService    srsReportRunService = new SrsReportRunService();         Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[]   parameterV...

Odata Patch operation using Postman

Script to update records using Postman. By default, system will consider the legal entity associated with the user added in Microsoft Entra ID applications for postman client id. Patch Operation: Example: URL:  {D365URL}/data/{Entity name}(dataAreaId='abcd', Unique field= 5637182305)//  Body: {     "Comment": "Test" }

Remove Prefix from a String in D365FO

Code to remove any specified prefix from a string value. (Example: Remove '0' from '000018743') public static str stringWithoutPrefix(str _strValue,str _prefixToRemove)     {         str s1 = _strValue;         str s2 = _prefixToRemove;         int i = 0;         int whereFound;         for(i= 0; i < strlen(s1); i++)         {             whereFound = strnFind(s1, s2 , 1, strLen(s1));             if(whereFound > 1)             {                 s1 = strdel(s1,1,1);             }         }         return s1;     }

Send Purchase Orders to Vendor collaboration for Vendor Review in D365FO

 Code snippet to send purchase orders for external vendor review (in  Vendor collaboration module)             try             {                 PurchTable purchTable = PurchTable::find(PurchId);                   PurchFormLetter purchFormLetter = PurchFormLetter::construct(DocumentStatus::ConfirmationRequest);                   purchFormLetter.update(purchTable, strFmt("Sent for vendor review",purchTable.PurchId));             }             catch (Exception::Deadlock)             {              }