Hi guys...
My requirement is to find the Financial dimension configuration format in d365.
internal final class RunnableClass
{
/// <summary>
/// Class entry point. The system will call this method when a designated menu
/// is selected or when execution starts and this class is set as the startup class.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
DimensionHierarchyIntegration dimensionHierarchyIntegration;
DimensionHierarchy dimensionHierarchy;
select * from dimensionHierarchy where dimensionHierarchy.Name == 'Default dimensions integration';
select * from dimensionHierarchyIntegration
where dimensionHierarchyIntegration.DimensionHierarchy == dimensionHierarchy.RecId;
info(strFmt(" theDisplay string is %1 :",dimensionHierarchyIntegration.DisplayString));
}
}
output:-
public static void main(Args _args)
{
str ledgerAccount;
int64 dimension = 68719705755;
ledgerAccount = LedgerDimensionFacade::getDisplayValueForLedgerDimension(dimension);
info(strFmt("%1", ledgerAccount));
}
Output:-
how to create ledgerDimension through code in X++.(MainAccount,Financial Dimension):-
public LedgerRecId createdimension()
{
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;
int i;
ledgerRecid Recid;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
DimensionServiceProvider DimensionServiceProvider = new DimensionServiceProvider();
LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract ValueContract;
List ListValueContract = new List(Types::Class);
str dimValue;
MainAccountNum mainAccount;
DimensionAttributeValueCombination dimensionAttributeValueCombination;
DimensionStorage dimStorage;
container conAttr = ["BusinessUnit", "Department"];
container conValue = ["001","002"];
mainAccount = "110115";
for (i = 1; i <= conLen(conAttr); i++)
{
dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));
if (dimensionAttribute.RecId == 0)
{
continue;
}
dimValue = conPeek(conValue,i);
if (dimValue != "")
{
dimensionAttributeValue =dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
// Add the dimensionAttibuteValue to the default dimension
valueSetStorage.addItem(dimensionAttributeValue);
}
result = valueSetStorage.save();
LedgerAccountContract.parmMainAccount(mainAccount);
LedgerAccountContract.parmValues(ListValueContract);
dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
Recid = LedgerDimensionFacade::ServiceCreateLedgerDimension(dimensionAttributeValueCombination.RecId, result);
info(strfmt("Ledger Dimension iS %1",Recid))
}
}
output:-68719705755
==================================================================================
Write X++ code to merge the financial dimension and ledger dimension in Dynamics 365 Finance and Operations:-
internal final class DAXTestClass
{
/// <summary>
/// Class entry point. The system will call this method when a designated menu
/// is selected or when execution starts and this class is set as the startup class.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
SubBillDeferralScheduleTable subBillDeferralScheduleTable;
MainAccountNum ledgerAccount;
DimensionAttributeLevelValueAllView dimAttrView;
DimensionAttribute dimensionAttribute;
container con = ["BusinessUnit", "Department"];
str businessunit,department;
RecId defaultfimension;
DAXTestClass dax = new DAXTestClass();
ledgerAccount = MainAccount::findByLedgerDimension(68719704257).MainAccountId;
for(int c=1; c<=conLen(con);c++)
{
select firstonly DisplayValue from dimAttrView
where dimAttrView.ValueCombinationRecId == 68719704257
join dimensionAttribute
where dimensionAttribute.RecId == dimAttrView.DimensionAttribute
&& dimensionAttribute.Name == any2Str(conPeek(con,c));
if(conPeek(con,c)== "BusinessUnit")
{
businessunit = dimAttrView.DisplayValue;
}
else if(conPeek(con,c)== "Department")
{
department = dimAttrView.DisplayValue;
}
}
defaultfimension = dax.createdimension(businessunit,department);
info(strFmt("ledgerDimension %1",defaultfimension));
}
public LedgerRecId createdimension(str businessunitid, str departmentid)
{
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;
int i;
ledgerRecid Recid;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
DimensionServiceProvider DimensionServiceProvider = new DimensionServiceProvider();
LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract ValueContract;
List ListValueContract = new List(Types::Class);
str dimValue;
MainAccountNum mainAccount;
DimensionAttributeValueCombination dimensionAttributeValueCombination;
DimensionStorage dimStorage;
container conAttr = ["BusinessUnit", "Department"];
container conValue = [businessunitid,departmentid];
mainAccount = "110115";
for (i = 1; i <= conLen(conAttr); i++)
{
dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));
if (dimensionAttribute.RecId == 0)
{
continue;
}
dimValue = conPeek(conValue,i);
if (dimValue != "")
{
dimensionAttributeValue =dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
// Add the dimensionAttibuteValue to the default dimension
valueSetStorage.addItem(dimensionAttributeValue);
}
result = valueSetStorage.save();
LedgerAccountContract.parmMainAccount(mainAccount);
LedgerAccountContract.parmValues(ListValueContract);
dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
Recid = LedgerDimensionFacade::ServiceCreateLedgerDimension(dimensionAttributeValueCombination.RecId, result);
}
return Recid;
}
}
======================================================================================
Update main account only:-
internal final class DAXFinUpdateClass
{
/// <summary>
/// Class entry point. The system will call this method when a designated menu
/// is selected or when execution starts and this class is set as the startup class.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
int64 defaultDimension = LedgerDimensionFacade::getDefaultDimensionFromLedgerDimension(68719705006);
str newmanin = LedgerDynamicAccountHelper::getAccountNumberFromDynamicAccount(110110);
int64 newledgerAccount = LedgerDimensionFacade::serviceCreateLedgerDimension(5637144576,defaultDimension,0,0);
Info(strFmt(" new ledger account is %1",newledgerAccount));
}
}
No comments:
Post a Comment