Create Default dimension using x++

The following job will get a DimensionAttributeValueSet record ID base on the a set of dimension values.

 

static void CreateDefaultDimensions(Args _args)
{
PurchTable purchTable;
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;

int i;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;

// Note that “Item” is not one of the default dimension,
// but DimensionAttributeValueSetStorage will handle it gracefully
container conAttr = [“Project”, “Vendor”]; // Dimensions
container conValue = [“1001”, “Ven-0046”]; // ¬†respective Values
str dimValue;

purchTable = purchTable::find(‘000471’);

for (i = 1; i <= conLen(conAttr); i++)
{
dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));

if (dimensionAttribute.RecId == 0)
{
continue;
}

dimValue = conPeek(conValue,i);

if (dimValue != “”)
{
// The last parameter is “true”. A dimensionAttributeValue record will be created if not found.
dimensionAttributeValue =
dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);

// Add the dimensionAttibuteValue to the default dimension
valueSetStorage.addItem(dimensionAttributeValue);
}
}

result = valueSetStorage.save();
purchTable.selectForUpdate(true);
ttsBegin;
purchTable.DefaultDimension = result;
purchTable.doUpdate();
ttsCommit;
}

Default dimension

Here is the sample Job to insert Default Dimension,It is just a sample job according to my client requirements, sharing just for an idea, it insert Business unit according to hardcoded p&l,

i used AxdDimensionUtil class for this purpose

 

// BU and vales are hardcoded as per requirments for INTECH

static void AXPsetFinancialDimensionToCustomer()
{
CustTable custTable;
container ledgerDimension;
DimensionDefault dimensionDefault;
int i, centerNum;
str centerValue, businessUnitValue, businessUnitValueParmeter;

// custTable = CustTable::find(‘10183’,true);
while select forUpdate custTable
{
businessUnitValueParmeter = ‘00000424’; // Only This Business Unit will Insert/Update
if(custTable.RecId)
{
ledgerDimension = AxdDimensionUtil::getDimensionAttributeValueSetValue(custTable.DefaultDimension);
i = conFind(ledgerDimension, “BusinessUnit”);
centerNum = conFind(ledgerDimension, “Center”);
centerValue = conPeek(ledgerDimension , (centerNum + 1));

if(centerValue == ‘100’ || centerValue == ‘1010’ || centerValue == ‘1020’)
{
businessUnitValue = ‘00000424’;
}
else if(centerValue == ‘102’ || centerValue == ‘103’ || centerValue == ‘106’ )
{
businessUnitValue = ‘00000421’;
}
else if(centerValue == ‘101’ || centerValue == ‘108’ || centerValue == ‘109’ )
{
businessUnitValue = ‘00000401’;
}
else if(centerValue == ‘704’ || centerValue == ‘AP PL’)
{
businessUnitValue = ‘00000222’;
}
else if(centerValue == ‘104’ || centerValue == ‘105’ || centerValue == ‘107’
|| centerValue == ‘CASPIAN PL’ || centerValue == ‘INTECH KSA’ || centerValue == ‘IRAQ PL’
|| centerValue == ‘MECA PL’ || centerValue == ‘UAE PL’ || centerValue == ‘UAE PnL’)
{
businessUnitValue = ‘00000423’;
}
else if(centerValue == ‘500’ || centerValue == ‘501’ || centerValue == ‘5010’
|| centerValue == ‘502’ || centerValue == ‘5020’ || centerValue == ‘503’
|| centerValue == ‘5030’ || centerValue == ‘504’ || centerValue == ‘5040’
|| centerValue == ‘505’ || centerValue == ‘506’ || centerValue == ‘702’
|| centerValue == ‘711’ || centerValue == ‘712’ || centerValue == ‘713’
|| centerValue == ‘SEN AP PL’ || centerValue == ‘SEN CORP’ || centerValue == ‘SEN FAC’
|| centerValue == ‘SEN OM PL’ || centerValue == ‘SEN US PL’ || centerValue == ‘SENSYS’)
{
businessUnitValue = ‘00000425’;
}
if(i == 0)
{
ledgerDimension = conPoke(ledgerDimension, 1, (conPeek(ledgerDimension, 1) +1));
ledgerDimension = conins(ledgerDimension,(conlen(ledgerDimension)+1),’BusinessUnit’);
ledgerDimension = conIns(ledgerDimension,(conLen(ledgerDimension)+1),businessUnitValue);
}
else
{
ledgerDimension = conPoke(ledgerDimension, (i+1),businessUnitValue );
}

ttsBegin;
dimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
custTable.DefaultDimension = dimensionDefault;
custTable.update();
ttsCommit;
info(strFmt(‘ Customer id = %1 , Business Unit = %2’,custTable.AccountNum , businessUnitValue));

}
else
{
info(‘Customer Not Found’);
}
businessUnitValue = ” ;
i = 0;
centerNum = 0;
centerValue = ”;
dimensionDefault = 0;
}
}