Tuesday, June 8, 2021

Finacial dimensions using ledger dimension / main account

Select * from objMainAccount
 inner join                from objDimensionAttributeValueCombination 
                where objDimensionAttributeValueCombination.MainAccount == objMainAccount.RecId
                      && objDimensionAttributeValueCombination.RecId == objGeneralJournalAccountEntry.LedgerDimension



static void Job38(Args _args)
{
GeneralJournalAccountEntry generalJournalAccountEntry; //Table that stores ledger transactions
BudgetTransactionLine BudgetTransactionLine;
//DimensionAttributeValueCombination dimAttrValueComb;
DimensionAttributeLevelValueAllView dimAttrView; //View that will display all values for ledger dimensions
DimensionAttribute dimAttr; //Main dimension attribute table
int i;
while select BudgetTransactionLine
{
//dimAttrValueComb = DimensionAttributeValueCombination::find(BudgetTransactionLine.LedgerDimension);
// setPrefix(int2str(i) + ". " + DimensionAttributeValueCombination::find(BudgetTransactionLine.LedgerDimension).DisplayValue);
select DisplayValue from dimAttrView
where dimAttrView.ValueCombinationRecId == BudgetTransactionLine.LedgerDimension join BackingEntityType from dimAttr
where dimAttr.RecId == dimAttrView.DimensionAttribute && dimAttr.BackingEntityType== tableName2id("DimAttributeOMDepartment");
info(strFmt("Department: %1,Combination: %2", dimAttrView.DisplayValue));//,dimAttrValueComb.DisplayValue));
// info(strfmt("%1" , dimAttrValueComb.DisplayValue));
// dimensionStorage = DimensionStorage::findById(gjAccEntry.LedgerDimension);
}
// setPrefix("Breakup for " + dimAttrValueComb.DisplayValue);
}


https://erpdax.wordpress.com/tag/cost-centre/ ( very important helpful link)

Dimension values from Ledger Dimension

Below code will get you the Default Dimension by passing the Ledger Dimension

public str getBusinessUnit(RecId _ledgerDimension)
{
 
// DimensionAttributeValueCombination stores the combinations of dimension values
// Any tables that uses dimension combinations for main account and dimensions
// Has a reference to this table’s recid
DimensionAttributeValueCombination dimAttrValueComb;
//GeneralJournalAccountEntry is one such tables that refrences DimensionAttributeValueCombination
GeneralJournalAccountEntry gjAccEntry;
// Class Dimension storage is used to store and manipulate the values of combination
DimensionStorage dimensionStorage;
// Class DimensionStorageSegment will get specfic segments based on hierarchies
DimensionStorageSegment segment;
int segmentCount, segmentIndex;
int hierarchyCount, hierarchyIndex;
str segmentName, segmentDescription;
SysDim segmentValue;
;
 
dimAttrValueComb = DimensionAttributeValueCombination::find(_ledgerDimension);
 
// Get dimension storage
dimensionStorage = DimensionStorage::findById(_ledgerDimension);
if (dimensionStorage == null)
{
throw error("@SYS83964");
}
 
// Get hierarchy count
hierarchyCount = dimensionStorage.hierarchyCount();
//Loop through hierarchies to get individual segments
for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)
{
 
//Get segment count for hierarchy
segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);
 
//Loop through segments and display required values
for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)
{
// Get segment
segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);
 
// Get the segment information
if (segment.parmDimensionAttributeValueId() != 0)
{
// Get segment name
segmentName = DimensionAttribute::find(DimensionAttributeValue::find(segment.parmDimensionAttributeValueId()).DimensionAttribute).Name;
//Get segment value (id of the dimension)
segmentValue = segment.parmDisplayValue();
if(segmentName =="CostCenter")            //Give the Dimension Name to that Dimension Value
{
return segmentValue;
}
}
}
}
return "";
}


Getting Dimension values from Default Dimension

From the below  we can get all the Default Dimension values:

Method 1:

DimensionAttributeValueSetStorage dimStorage;
Counter i;
str dimensionValue;
RefRecId defaultdim;
DirPartyName dimensionValue1;
 
defaultdim = 5637176154; //this number is basically from field DefaultDimension
dimStorage = DimensionAttributeValueSetStorage::find(defaultdim);
 
for (i=1 ; i&amp;lt;= dimStorage.elements() ; i++)
{
if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name=='BusinessUnit') //Give the Attribute you want to get the value for.
{
dimensionValue = dimStorage.getDisplayValueByIndex(i);
dimensionValue1 = DirPartyTable::findRec(VendTable::find(dimensionValue).Party).Name;//To get the Vend Name
break;
}
}
info(strFmt(&quot;Business Unit: %1&quot;,dimensionValue));


Method 2:

DimensionAttributeValueSet dimAttrValueSet;
DimensionAttributeValueSetItem dimAttrValueSetItem;
DimensionAttributeValue dimAttrValue;
DimensionAttribute dimAttribute;
RefRecID dimensionSetRecID;
Name attributeName;
;
dimensionSetRecID = 5637176154; //this number is basically from field DefaultDimension
attributeName = 'BusinessUnit'; //put here the name of dimension
dimAttrValueSet = DimensionAttributeValueSet::find(dimensionSetRecID);
 
select dimAttrValueSetItem
where dimAttrValueSetItem.DimensionAttributeValueSet == dimAttrValueSet.RecId
join dimAttrValue
where dimAttrValue.RecId == dimAttrValueSetItem.DimensionAttributeValue
join dimAttribute
where dimAttribute.RecId == dimAttrValue.DimensionAttribute
&amp;amp;&amp;amp; dimAttribute.Name == attributeName;
info(strFmt(&quot;Business Unit: %1----%2&quot;,dimAttrValue.getValue(),dimAttrValue.getName()));


OR

Passing current record buffer

[SysClientCacheDataMethodAttribute(true)]
display DimensionValue BusinessUnit(InventJournalTrans _inventJournalTrans)//Passing current record buffer
{
 
DimensionAttributeValueSetStorage dimStorage;
Counter i;
DimensionValue dimensionValue;
RefRecId defaultdim;
 
defaultdim = _inventJournalTrans.DefaultDimension; //this number is basically from field DefaultDimension
dimStorage = DimensionAttributeValueSetStorage::find(defaultdim);
 
for (i=1 ; i&amp;lt;= dimStorage.elements() ; i++)
{
if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name=='BusinessUnit') //Give the Attribute you want to get the value for.
{
dimensionValue = dimStorage.getDisplayValueByIndex(i);
break;
}
}
return dimensionValue;

}

OR

Adding the Code at Global Class


Eg: To use this method:
tempTable.DimensionValue= getDefaultDimensionValue("BusinessUnit",prodTable.DefaultDimension);
//To Get the default dimension value by using default dimension id
static str 50 getDefaultDimensionValue(str _dimName,DimensionDefault _defaultDimension)
{
 DimensionAttributeValueSetStorage dimStorage;
 CustTable custTable;
 Counter i;
 str returnValue;
 dimStorage = DimensionAttributeValueSetStorage::find(_defaultDimension);
 for (i=1 ; i<= dimStorage.elements() ; i++)
 {
 if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == _dimName)
 {
 returnValue = dimStorage.getDisplayValueByIndex(i);
 break;
 }
 }
 return returnValue;
}

No comments:

Post a Comment

Finacial dimensions using ledger dimension / main account

Select * from objMainAccount  inner join                from objDimensionAttributeValueCombination                  where objDimensionAttrib...