Posts

Showing posts from 2021

How to Import Records from Excel Using X++ Code in D365FO

  How to Import Records from Excel Using X++ Code in D365FO   Include the below namespace in X++ code it will requires to import Excel. Using System.IO; Using OfficeOpenXml; Using OfficeOpenXml.ExcelPackage; Using OfficeOpenXml.ExcelRange;   In addition to the basic reference, include (Directory and DirectoryUpgrade Packages) X++ Code: Using System.IO; Using OfficeOpenXml; Using OfficeOpenXml.ExcelPackage; Using OfficeOpenXml.ExcelRange; class ReadExcel {   public static void main(Args _args)    {     Int id;     Str Name;      System.IO.Stream stream;       ExcelSpreadsheetName sheet;              FileUploadBuild fileUpload,fileUploadBuild;       DialogGroup dialogUploadGroup;       FormBuildControl formBuildControl;   ...

D365 FO X++ and the dangers of converting enum to string

 D365 FO X++ and the dangers of converting enum to string When converting an enum to string in X++. If you are using enum2str() the result depends on the   preferred locale. PurchRFQType prt = PurchRFQType::Received; str result = enum2Str(prt); info(result);     If you are using enum2symbol the resulting string to be the name of the enum value   PurchRFQType prt = PurchRFQType::Received; str result = enum2Symbol(enumNum(PurchRFQType), prt); info(result);   // info   "Received" regardless of the locale  

D365 FO Packing slip using X++ and taking current packing slip record

  D365 FO Packing slip using X++ and taking current packing slip record static void postPackingSlip(Args _args) { SalesFormLetter salesFormLetter; SalesTable salesTable; SalesId salesId = ‘SO00001’; System.Exception error; str strError; CustPackingSlipJour custPackingSlipJour; ;   ttsBegin; try { salesTable = SalesTable::find(salesId);   if (salesTable && salesTable.SalesStatus == SalesStatus::Backorder) { salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip); salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::PackingSlip, AccountOrder::None, NoYes::No, NoYes::No, NoYes::No);     custPackingSlipJour = salesFormLetter.parmJournalRecord(); info(strFmt(‘New Packing Slip #:%1 successfully created for Sales Order #:%2’, custPackingSlipJour.PackingSlipId, custPackingSlipJour.SalesId));   } else { info(strFmt(‘%1 does not exsists or null in the system, please try again!...

Rounding the real value D365 FO using X++

  Rounding the real value D365 FO using X++ To perform a round in AX in real using the function decround.   static void Job1(Args _args) {     int i, ii;     real r = 334.55, r2 = 334.14;     ;       i = decround(r, 0);     ii = decround(r2, 0);       // It shows 335, 334     info(strfmt("%1, %2", i, ii)); }

Read properties of table fields using X++ code

  Read properties of table fields using X++ code static void checkProperties(Args _args) {     DictTable        dictTable;     DictField        dictField;     int              i, cnt;        dictTable = new DictTable(tableNum(CustTable));     cnt = dictTable.fieldCnt();     for (i= 1; i<=cnt;i++)     {         dictField = new DictField(tableNum(CustTable),dictTable.fieldCnt2Id(i));         if (dictField.mandatory())         {             info (strFmt("Field %1 is mandatory.",dictField.label()));         }     } ...

Create a production order for a sales order line using X++ in D365

  Create a production order for a sales order line using X++ in D365 If you want to create a production order for a sales order line, use the following code   static void createProdTableForSalesLine(Args _args) {     SalesLine salesLine = SalesLine::findInventTransId('011748');     ProdTable prodTable;       prodTable.initValue();     prodTable.initFromCaller(salesLine);       prodTable.insert(); }

Create production order in D365FO X++

  Create production order in D365FO   X++ static void   CreateProdOrder(Args _args) {     ProdQty          qty      = 10;     ItemId           item     = 'D0005';       ProdTable        prodtable;     InventTable      inventTable;     InventDim        inventDim;     ;       // Initialize InventTable     inventTable = inventTable::find(item);       // Initialize the base values     prodtable.initValue();     prodtable.initFromInventTable(inventTable);       prodtable.ItemId            ...

RelationshipType in D365 FO

  RelationshipType in D365 FO In  AOT > Data Dictionary > Tables > Table > Relations, you can set the value of the RelationshipTypeproperty of the new relation. The following table describes the elements of the RelationshipType property. Element name Description Automatic inference NotSpecified Often the default value for the  RelationshipType property. When the  RelationshipType  property has the value NotSpecified , the system infers an appropriate value. The system infers the value in the following sequence: 1.                Specialization 2.               Link 3.               Composition 4.             ...

Cardinality and RelatedTableCardinality table relation property in D365 FO

  Cardinality and RelatedTableCardinality table relation property in D365 FO Cardinality is the property which explains about nature of the relationship between two tables on the related table. For example: ZeroOne: You will select this, provided child Table/related table can either have no record or have only one related record (Fetch Mode is 1:1). ExactlyOne: You will select this, provided child Table/related table can have only one related record (Fetch Mode is 1:1).  ZeroMore: You will select this, provided child Table/related table can either have no record or more than one related record (Fetch Mode is 1:n). OneMore: You will select this, provided child Table/related table can have more than one related record (Fetch Mode is 1:n). Cardinality specifies how many instances of SalesLine row can be related to a single instance of SalesTable row. ZeroMore means that for every sale order, there can be zero, or more sales lines related to it. If the business require...

X++ Create Purchase order from Sales order in D365 FO

  X++ Create Purchase order from Sales order in D365 FO TmpPurchLinePrice tmpPurchLinePrice; PurchCreateFromSalesOrder PurchCreateFromSalesOrder; SalesTable salesTable; ; salesTable = salesTable::find(“SO0000009”); tmpPurchLinePrice.clear(); tmpPurchLinePrice.initValue(); tmpPurchLinePrice.Included = NoYes::Yes; tmpPurchLinePrice.LineAmount = 100; tmpPurchLinePrice.PurchUnit = “EA”; tmpPurchLinePrice.PriceUnit = 12; tmpPurchLinePrice.CurrencyCode = “USD”; tmpPurchLinePrice.ItemId = “0001882”; tmpPurchLinePrice.PurchQty = 2; tmpPurchLinePrice.AccountNum = “V000002“; tmpPurchLinePrice.SalesId = “SO0000009”; tmpPurchLinePrice.SalesLineRefRecId = 5637146077; tmpPurchLinePrice.LineNum = 2;   if (tmpPurchLinePrice.validateWrite()) { tmpPurchLinePrice.insert(); }   // Now create the Purchase Order purchCreateFromSalesOrder = PurchCreateFromSalesOrder::construct(); purchCreateFromSalesOrder.parmCallerRecord(salesTable); purchC...

X++ code to create Direct Delivery Purchase order in D365FO

  X++ code to create Direct Delivery Purchase order in D365FO class DirectDeliveryPO { /// <summary> /// Runs the class with the specified arguments. /// </summary> /// <param name = “_args”>The specified arguments.</param> public static void main(Args _args) { PurchAutoCreate purchAutoCreate; PurchCreateFromSalesOrder purchCreateFromSalesOrder; TmpPurchLinePrice tmpPurchLinePrice; SalesTable salesTable; SalesLine salesLine; InventTable inventTable; VendAccount prevVendAccount; LineNum lineNum = 0; SalesId salesId = ‘SO000081’; str curCompany = curExt();   try { ttsbegin;   while select salesLine order by inventTable.PrimaryVendorId where salesLine.SalesId == salesId join inventTable where inventTable.ItemId == salesLine.ItemId { if (prevVendAccount && prevVendAccount != inventTable.PrimaryVendorId) { purchAutoCreate = PurchAutoCreate::construct(tmpPurchLinePrice, purchCreateFrom...

Data Migration tool : AX 2009 to D365

Data Migration tool : AX 2009 to D365FO   While click on generate mapping in data migration tool in AX 2009  getting the error "The given value of type string from datasource cannot be converted to type nvarchar of specific target column". The issue of String error should be gone after increasing the length of DMTName EDT.

X++ code to get ledgerDimension for MainAccount

Image
  X++ code to get ledgerDimension for MainAccount

X++ Code to enable or disable dialogfield in UIBuilder class in D365FO

  X++ Code to enable or disable dialogfield in UIBuilder class in D365FO   class disableFieldUIBuilder extends SysOperationAutomaticUIBuilder {       private disableFieldContract testContract;       private DialogField dialogCode;       /// <summary>     ///       /// </summary>       public void postBuild()     {           testContract;= this.dataContractObject();           super();         dialogCode = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(disableFieldContract , parmCode));           dialogCode.enabled(false);       }   }

X++ code to check Fiscal calendar period in D365FO

  X++ code to check Fiscal calendar period in D365FO public static boolean findFiscalCalendarPeriod(TransDate _date) {         RecId calendarRecId;         FiscalCalendarPeriod fiscalCalendarPeriod;         calendarRecId = Ledger::fiscalCalendar(CompanyInfo::find().RecId);         fiscalCalendarPeriod = FiscalCalendarPeriod::findPeriodByCalendarDate(calendarRecId, _date, FiscalPeriodType::Operating);            if (_date)          {               if (!fiscalCalendarPeriod)             {                 return checkFailed(strFmt("@SYS17614",date2StrUsr(_date,DateFlags::FormatAll))); ...