Tuesday, 15 October 2013

Job For dimensions

Code to get Dimension value based on Default dimension 
select * from defaultDimensionView
        where defaultDimensionView.DefaultDimension ==  custTrans.DefaultDimension;   

    grossMarginCashFlowTmp.Division         =   defaultDimensionView.DisplayValue;


dimensions (job)
static void DEV_Dimension(Args _args)
{
CustTable custTable = CustTable::find(“1101″);
DimensionAttributeValueSetStorage dimStorage;
Counter i;
dimStorage = DimensionAttributeValueSetStorage::find(5637144576);
//recid of 1101
for (i=1 ; i<= dimStorage.elements() ; i++)
{
info(strFmt(“%1 = %2 = %3 “, DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name,
dimStorage.getDisplayValueByIndex(i),dimStorage.getValueByDimensionAttribute(i)));
}
}
 //////////////////////////////////////////////////
static void Job3(Args _args)
{
/// <summary>
/// Inserts common data into the template table buffer.
/// </summary>
DocuRef DocuRef;
purchTable purchTable;
DimensionAttributeValueSetStorage dimStorage;
Counter i;
DimensionAttributeValueSet dimAttrValueSet;
DimensionAttributeValueSetItem dimAttrValueSetItem;
DimensionAttributeValue dimAttrValue;
DimensionAttribute dimAttr;
Common dimensionValueEntity;
//VendPurchOrderJour VendPurchOrderJour;
int64 PurchRecid,PurchDim,TableId;
PurchIdBase purchID;
str st,c;
PurchPurchaseOrderHeader PurchPurchaseOrderHeader;
// this.initializePurchPurchaseOrderHeader();
/*while select purchTable
{
dimStorage = DimensionAttributeValueSetStorage::find(PurchTable.DefaultDimension);
//PurchPurchaseOrderHeader.DimValue2 = DimensionAttribute::find(dimStorage.getAttributeByIndex(1)).Name;
PurchPurchaseOrderHeader.DimValue1 = dimStorage.getDisplayValueByIndex(1);
PurchPurchaseOrderHeader.Dim = DimensionAttribute::find(dimStorage.getAttributeByIndex(1)).Name;
while select DocuRef where DocuRef.RefRecId == purchTable.RecId && DocuRef.RefCompanyId == purchTable.dataAreaId
&& DocuRef.RefTableId == purchTable.TableId
PurchPurchaseOrderHeader.Notes1 = DocuRef.Notes;
}*/
while select PurchTable{
// if(purchTable.PurchId == VendPurchOrderJourloc.PurchaseOrderId)
purchID = VendPurchOrderJour::findbyPurchaseOrderId(PurchPurchaseOrderHeader.PurchaseOrderId).PurchId;
purchID = “000402″;
PurchRecid = purchTable::find(purchID).RecId;
PurchDim = purchTable::find(purchID).DefaultDimension;
TableId = PurchReqLine::findByPurchId(purchID).PurchReqTable;
c = PurchReqTable::find(TableId).PurchReqId;
PurchPurchaseOrderHeader.PurchReqId = c;
while select DocuRef where DocuRef.RefRecId == PurchRecid && DocuRef.RefCompanyId == purchTable.dataAreaId
&& DocuRef.RefTableId == purchTable.TableId
{
PurchPurchaseOrderHeader.Notes1 = DocuRef.Notes;
}
dimAttrValueSet = DimensionAttributeValueSet::find(PurchDim);
// Find all of the ‘value set items’ linked against the ‘value set’
while select dimAttrValueSetItem where dimAttrValueSetItem.DimensionAttributeValueSet == dimAttrValueSet.RecId
{
// Find the dimension ‘value’ (DimensionAttributeValue) that the set item points to.
dimAttrValue = DimensionAttributeValue::find(dimAttrValueSetItem.DimensionAttributeValue);
// Find the underlying attribute.
dimAttr = DimensionAttribute::find(dimAttrValue.DimensionAttribute);
// Use the helper class to obtain a reference to the underlying entity (can be anything)
dimensionValueEntity = DimensionDefaultingControllerBase::findBackingEntityInstance(
curext(),
dimAttr,
dimAttrValue.EntityInstance);
if(dimAttr.Name == “CostCenter”)
{
PurchPurchaseOrderHeader.Dim = dimAttr.Name;
PurchPurchaseOrderHeader.DimValue1 = dimAttrValue.getValue();
}
//info(dimAttr.Name + ‘ ‘ + dimAttrValue.getValue());
}
}
//purchPurchaseOrderHeader.insert();
print PurchPurchaseOrderHeader.Dim;
print PurchPurchaseOrderHeader.DimValue1;
pause;
}
 ///////////////////////
static void DEV_Dimensionnew(Args _args)
{
// PurchTable PurchTable = PurchTable::find(“000404″);
DimensionAttributeValueSetStorage dimStorage;
Counter i;
PurchTable PurchTable;
while select PurchTable
dimStorage = DimensionAttributeValueSetStorage::find(PurchTable.DefaultDimension);
//for (i=1 ; i<= dimStorage.elements() ; i)
//{
info(strFmt(“%1 = %2 = %3″, DimensionAttribute::find(dimStorage.getAttributeByIndex(1)).Name,
dimStorage.getDisplayValueByIndex(1),dimStorage.getDisplayValueByDimensionAttribute(1)));
// getDisplayValueByDimensionAttribute
// }
}
 ///////////
static void getLedgerDimensionUsingDefaultDimensions(Args _args)
{
PurchTable PurchTable;
DocuRef DocuRef;
PurchPurchaseOrderHeader PurchPurchaseOrderHeader;
DimensionAttributeValueSet dimAttrValueSet;
DimensionAttributeValueSetItem dimAttrValueSetItem;
DimensionAttributeValue dimAttrValue;
DimensionAttribute dimAttr;
Common dimensionValueEntity;
;
while select PurchTable{
// while select DocuRef where DocuRef.RefRecId == purchTable.RecId && DocuRef.RefCompanyId == purchTable.dataAreaId
// && DocuRef.RefTableId == purchTable.TableId
// {//&& purchTable.PurchId == “000400″;
// PurchPurchaseOrderHeader.Notes1 = DocuRef.Notes;
// }
dimAttrValueSet = DimensionAttributeValueSet::find(PurchTable.DefaultDimension);
// Find all of the ‘value set items’ linked against the ‘value set’
while select dimAttrValueSetItem where dimAttrValueSetItem.DimensionAttributeValueSet == dimAttrValueSet.RecId
{
// Find the dimension ‘value’ (DimensionAttributeValue) that the set item points to.
dimAttrValue = DimensionAttributeValue::find(dimAttrValueSetItem.DimensionAttributeValue);
// Find the underlying attribute.
dimAttr = DimensionAttribute::find(dimAttrValue.DimensionAttribute);
// Use the helper class to obtain a reference to the underlying entity (can be anything)
dimensionValueEntity = DimensionDefaultingControllerBase::findBackingEntityInstance(
curext(),
dimAttr,
dimAttrValue.EntityInstance);
if(dimAttr.Name == “CostCenter”)
{
PurchPurchaseOrderHeader.Dim = dimAttr.Name;
PurchPurchaseOrderHeader.DimValue1 = dimAttrValue.getValue();
}
//info(dimAttr.Name + ‘ ‘ + dimAttrValue.getValue());
}
}
print PurchPurchaseOrderHeader.Dim;
print PurchPurchaseOrderHeader.DimValue1;
//print PurchPurchaseOrderHeader.Notes1;
pause;
}

=====================================================================
    static void Job7(Args _args)
    {
         ProjTable   ProjTable;
         Counter     i;
         container   conDim;
   
         ProjTable = ProjTable::find("10005");     //  To display value for ProjectId "10005" only
         conDim = AxdDimensionUtil::getDimensionAttributeValueSetValue(ProjTable.DefaultDimension);
   
         for (i=1 ; i<= conLen(conDim) ; i++)
         {
              info(conPeek(conDim,i));
         }   

    }
=====================================================================
Create Default Dimension :
static DimensionDefault createDefaultDimension(container _attr, container _value, boolean _createIfNotFound = true)
     {
         DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
         DimensionDefault                               result;
         int                                                      i;
         DimensionAttribute                            dimensionAttribute;
         DimensionAttributeValue                   dimensionAttributeValue;
         //_attr is dimension name in table DimensionAttribute
         container               conAttr =   _attr;
         container               conValue = _value;
         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 != "")
             {
                 // _createIfNotFound is "true". A dimensionAttributeValue record will be created if not found.
                 dimensionAttributeValue =
                         dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,_createIfNotFound);
   
                 // Add the dimensionAttibuteValue to the default dimension
                 valueSetStorage.addItem(dimensionAttributeValue);
             }
         }
         result = valueSetStorage.save();
         return result;
     }
======================================================================
ConstructDimension  :

    static DimensionDefault constructDimension(ProjId   projId)
    {
        ProjTable                           ProjTable;
        Counter                             i;
        container                           conDim;
        container                           value, Value1;
        DimensionAttributeValueSetStorage   storage;
        int                                 attributeCount, attributeIndex;
        str                                 attributeName, attributeValue;
        str                                 dimValue;
        DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
        DimensionDefault                    result;
        DimensionAttribute                  dimensionAttribute;
        DimensionAttributeValue             dimensionAttributeValue;
        boolean _createIfNotFound = true;
   
        changeCompany('USMF')
        {
            ProjTable = ProjTable::find(projId);
        }
    
        value = conNull();
        Value1 = conNull();
        // Get storage
        storage = DimensionAttributeValueSetStorage::find(ProjTable.DefaultDimension);
   
        // Add attribute count
        attributeCount = storage.elements();
        //value += attributeCount;
   
        // Add attributes
        for (attributeIndex = 1; attributeIndex <= attributeCount; attributeIndex++)
        {
            // Add attribute name
            attributeName = DimensionAttribute::find(storage.getAttributeByIndex(attributeIndex)).Name;
            value += attributeName;
   
            // Add attribute value
            attributeValue = DimensionAttributeValue::find(storage.getValueByIndex(attributeIndex)).getValue();
            value1 += attributeValue;
        }
   
        for (i = 1; i <= conLen(Value); i++)
        {
            dimensionAttribute = dimensionAttribute::findByName(conPeek(Value,i));
   
            if (dimensionAttribute.RecId == 0)
            {
                continue;
            }
   
            dimValue = conPeek(Value1,i);
   
            if (dimValue != "")
            {
                // _createIfNotFound is "true". A dimensionAttributeValue record will be created if not found.
                //changeCompany('USRT')
                {
                    dimensionAttributeValue =
                            dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,_createIfNotFound);
   
                    // Add the dimensionAttibuteValue to the default dimension
                    valueSetStorage.addItem(dimensionAttributeValue);
                }
            }
        }
        return valueSetStorage.save();
   
   
    }

No comments:

Post a Comment