Showing posts with label Default Dimension. Show all posts
Showing posts with label Default Dimension. Show all posts

Monday, May 21, 2018

How to write a generate method to map the default dimension

[DMFTargetTransformationAttribute(true),DMFTargetTransformationDescAttribute("@DMF1365"),
DMFTargetTransformationSequenceAttribute(24)
,DMFTargetTransFieldListAttribute([fieldStr(DMFLedgerJournalEntity,CICDepartments),fieldStr(DMFLedgerJournalEntity,CICProfitCenter),fieldStr

(DMFLedgerJournalEntity,CICDivisions)])
]
public container CICgenerateDimension(boolean _stagingToTarget = true)
{
    container                       res,varContainer;
    Counter                         varCounter=0;
    RecId                           retValueOfDefDimension;


    if (_stagingToTarget)
    {
        varContainer = [0];

        //assigning one dimension
        if(entity.CICDepartments)
        {
            varContainer += ['Department',entity.CICDepartments];
            varCounter++;//increase on ssignmnet of each dimension
        }

        //assigning 2nd dimension
        if(entity.CICProfitCenter)
        {
            varContainer += ['ProfitCenter',entity.CICProfitCenter];
            varCounter++;//increase on assignmnet of each dimension
        }

        if(entity.CICDivisions)
        {
           //assigning 3rd dimension
            varContainer += ['Divisions',entity.CICDivisions];
            varCounter++;//increase on assignmnet of each dimension
        }
        //so on.. you can pass any number of dimensions

        //prepare container
        varContainer = conPoke(varContainer,1,varCounter);

        //pass continer and get back value generated
        retValueOfDefDimension = AxdDimensionUtil::getDimensionAttributeValueSetId(varContainer);

        //Return the default dimension
        if(retValueOfDefDimension)
            res=[retValueOfDefDimension];         

    }
    return res;
}


-----------------------------------------------------------------------------------------------------------------
//assign the return value to the target table field in getReturnFields method


        case methodStr(DMFLedgerBalanceEntityClass, CICgenerateDimension) :
        con += [fieldstrToTargetXML(fieldStr(LedgerJournalTrans, DefaultDimension))];
        break;

How to generate the default dimension with the combination of dimension values using X++

Method 1 :-
static void DefaultDimension(Args _args)
{
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;

int i;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
container conAttr = ['Department','ProfitCenter' ,'Divisions'];
container conValue = ['CE', 'HO', 'GL'];
str dimValue;

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);
info("%1",dimensionAttributeValue);
}
}

result = valueSetStorage.save();
info("%1",result);
}
--------------------------------------------------------------------------------------------------------------------------

Method 2

 static void DefaultDimension(Args _args)
 {

    container   varContainer;
    Counter     varCounter=0;
    RecId       retValueOfDefDimension;
    ;
    
    varContainer = [0];
    
    //assigning one dimension
    varContainer += ["Department","025"];
    varCounter++;//increase on assignmnet of each dimension
    
    //assigning 2nd dimension
    varContainer += ["CostCenter","010"];
    varCounter++;//increase on assignmnet of each dimension
    
    //so on.. you can pass any number of dimensions
    
    //prepare container
    varContainer = conPoke(varContainer,1,varCounter);
    
    //pass continer and get back value generated
    retValueOfDefDimension = AxdDimensionUtil::getDimensionAttributeValueSetId(varContainer);
    
    //display just for demo puprose. in real practice simply assign it to table field(s)
    if(retValueOfDefDimension)
        info(strFmt('You can verify record with RecId %1 in Table DimensionAttributeValueSetItem by filtering on field DimensionAttributeValueSet.',retValueOfDefDimension));    
}

How to enable the dimension fields based on the Item selected on the form.

[Form] public class KMTShipFromWarehouses extends FormRun {     InventDimCtrl_Frm_EditDimensions        inventDimFormSetup;     /// ...