Wednesday, April 17, 2024

Updating Business Unit Value in Ledger Dimension using X++ in Dynamics 365 Finance and Operations

In Dynamics 365 Finance and Operations, ensuring consistency across ledger dimensions is crucial for accurate financial management. One common scenario involves updating the business unit value in the ledger dimension to reflect changes made in the offset ledger dimension.

Our blog explores a streamlined approach to meet this requirement seamlessly.





** Our provided code, tailored for business unit updates in ledger dimensions, exemplifies a flexible to a other dimensional attributes. Whether it's modifying cost centers, departments, or any other dimension, our framework seamlessly adapts, simply we have to change the respective attribute name.



[ExtensionOf(tablestr(LedgerJournalTrans))]
 public class ledgerJournalTrans_Table_Extension
{
   public void modifiedField(FieldId _fieldId)
   {   
		next modifiedField( _fieldId;
		switch (_fieldId)
		{
			DimensionAttributeLevelValueAllView dimensionAttributeLevelValueAllViewloc,dimensionAttributeLevelValueAllView;
			RecId defaultAccount;
			LedgerJournalTrans ledgerJournalTrans;
			
			case fieldNum(LedgerJournalTrans, OffsetLedgerDimension): 
			select DimensionAttributeLevelValueAllViewloc        
			   where DimensionAttributeLevelValueAllViewloc.ValueCombinationRecId==this.OffsetLedgerDimension  
				&& DimensionAttributeLevelValueAllViewloc.DimensionAttribute==DimensionAttribute::findByName("BusinessUnit").RecId;  
				 
			defaultAccount = LedgerDefaultAccountHelper::getDefaultAccountFromLedgerDimension(this.LedgerDimension); 

			DimensionAttributeValueSetStorage defaultDimensionValues = DimensionAttributeValueSetStorage::find(this.LedgerDimension); 

			while  select dimensionAttributeLevelValueAllView      
			  where dimensionAttributeLevelValueAllView.ValueCombinationRecId==this.LedgerDimension     
			{           
			  defaultDimensionValues.addItem(DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::find(dimensionAttributeLevelValueAllView.DimensionAttribute),
							   dimensionAttributeLevelValueAllView.DisplayValue, false, true));                    
			}             
			defaultDimensionValues.addItem(DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::findByName("BusinessUnit")
							,DimensionAttributeLevelValueAllViewloc.DisplayValue, false, true));      
			Recid newLedgerDimension = LedgerDimensionFacade::serviceCreateLedgerDimension(defaultAccount, defaultDimensionValues.save()); 
				   
			this.LedgerDimension=newLedgerDimension;
		}
	}
}

Tuesday, April 16, 2024

Add new ranges for static query based report.

 

The blog addresses a requirement to update the "Mcrholdorder" report in D365FO by implementing new date ranges for certain fields. This static query-based report needs modification to accommodate the specified changes efficiently.

in my scenario i have to add a rate ranges for table "McrHoldCodeTrans" field "CreateddateTime".

 [extensionOf(classStr(MCROrderHoldController))]
public void preRunModifyContract() { Query query; SrsReportRdlDataContract contract; // get the query from contract. query = this.parmReportContract().parmQueryContracts().lookup(this.getFirstQueryContractKey()); // get the contract object. contract = this.parmReportContract().parmRdlContract(); // startDate and end date values from contract dialog. startDate = contract.getParameter(#parameterFromDate).getValueTyped(); endDate = contract.getParameter(#parameterToDate).getValueTyped(); // pass the table and field on which field we have to apply ranges on. // if we want to add or join any data source with standard static query and send the created query in the parameters. SrsReportHelper::addFromAndToDateRangeToQuery(query,startDate,endDate, TableNum(MCRHoldCodeTrans), fieldNum(MCRHoldCodeTrans, CreatedDateTime)); }


Call API using x++ D365FO

 System.Net.HttpWebRequest    request; System.Net.HttpWebResponse   response; System.IO.Stream             dataStream; System.IO.StreamReade...