/// <summary> /// replace specific financial dimension value in DefaultDimension based on the LedgerParameters setup /// </summary> /// <param name = "_defaultDimensionFrom">DefaultDimension recId the value should be taken from</param> /// <param name = "_defaultDimensionTo">DefaultDimension recId the value should be assigned to</param> /// <returns>returns new DefaultDimension recId if conditions are met</returns> public static DimensionDefault replaceDefaultDim(DimensionDefault _defaultDimensionFrom, DimensionDefault _defaultDimensionTo) { if(!_defaultDimensionFrom) { return _defaultDimensionTo; } LedgerParameters ledgerParameters = LedgerParameters::find(); if (ledgerParameters.DepartmentSetFinancialDimension && ledgerParameters.DepartmentDimensionAttribute) { DimensionAttribute dimAttr; DimensionAttributeValue dimAttrValue; DimensionAttributeValueSetStorage davss; davss = DimensionAttributeValueSetStorage::find(_defaultDimensionTo); dimAttr = DimensionAttribute::find(ledgerParameters.DepartmentDimensionAttribute); DimensionAttributeValueSetStorage dimStorage = DimensionAttributeValueSetStorage::find(_defaultDimensionFrom); DimensionValue dimValue = dimStorage.getDisplayValueByDimensionAttribute(dimAttr.RecId); dimAttrValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttr, dimValue); if(dimAttrValue && !davss.containsDimensionAttributeValue(dimAttrValue.RecId)) { davss.addItem(dimAttrValue); return davss.save(); } } return _defaultDimensionTo; }
This blog is contains coding reference related to Microsoft AX 2012 and D365 finance and operations and Power platform
Showing posts with label Variables. Show all posts
Showing posts with label Variables. Show all posts
Tuesday, May 25, 2021
Set Financial Dimensions by X++ code in AX 2012/Setting one Dimension value in the combination
Friday, April 30, 2021
Conversion from UTCDateTime to Date or Time in AX
Here is an example of correct conversion between UTCDateTime value and Date and Time value which is associated with user preferred time zone: public static void testDateTimeConversion() { utcDateTime dateTime; date dateInUserTimeZone; TimeOfDay timeInUserTimeZone; dateTime = DateTimeUtil::utcNow(); dateInUserTimeZone = DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(dateTime, DateTimeUtil::getUserPreferredTimeZone())); timeInUserTimeZone = DateTimeUtil::time(DateTimeUtil::applyTimeZoneOffset(dateTime, DateTimeUtil::getUserPreferredTimeZone())); dateTime = DateTimeUtil::newDateTime(dateInUserTimeZone, timeInUserTimeZone, DateTimeUtil::getUserPreferredTimeZone()); }
Monday, April 26, 2021
UserConnection in D365fo
Its used when we need to commit our transaction wehen standared code doesn't Commit.
example :SalesQuotationEditLinesForm_Sales_Send > checkSales() , COC and try to write
custom insert or update operation here while validation is failed our transactions doesn't commit
static void KlForRecordInserted(Args _args) { UserConnection userConnection; CustTable custTable; ; ttsbegin; userConnection = new userConnection(); custTable.clear(); custTable.initValue(); custTable.AccountNum = "000020"; custTable.Name = "My Test Customer"; custTable.setConnection(userConnection); // set userconnection custTable.insert(); throw error("An error that causes a rollback"); ttscommit; }
Sunday, April 11, 2021
Access public variables in extension class using chain of command
When you wrap a method, you can also access public and protected methods and variables of the base class. CustInvoiceJour is a base class variable hence you will be able to access it. Eg. [ExtensionOf(classStr(SalesConfirmJournalCreate))] Final class SalesConfirmJournalCreate_Extension { protected void createJournalHeader() { next createJournalHeader(); //It's as simple as this: custConfirmJour.SalesBalance = 0; } if gets an error, It's an old bug with variable names. Declare new one and use it: protected void createJournalHeader() { next createJournalHeader(); CustConfirmJour custConfirmJourLocal = custConfirmJour; custConfirmJourLocal.MyField = 'blah-blah'; } }
Thursday, January 14, 2016
AX 2012: Refresh form by Code in AX
Refresh form by Code X++
Add this code in form level
#Task
element.task(#taskF5);
Subscribe to:
Posts (Atom)