Showing posts with label dimension. Show all posts
Showing posts with label dimension. Show all posts

Monday, March 13, 2017

Get dimension name and value in Ax2012

Hi Guys,

Here is another code snippet to get Dimension value and name by dimension:

static DimensionValue Ale_getDefaultDimensionValue(DimensionDefault   _dimensionDefault , Name  _defaultDimensionName)
{
    DimensionAttributeValueSet      dimAttrValueSet;
    DimensionAttributeValueSetItem  dimAttrValueSetItem;
    DimensionAttributeValue         dimAttrValue;
    DimensionAttribute              dimAttr;
    Common                          dimensionValueEntity;
    DimensionValue                  dimValue;
    Name                                   dimName;
    container                           dimNameValue;
    ;
    dimAttrValueSet = DimensionAttributeValueSet::find(_dimensionDefault);

    while select DimensionAttributeValue from dimAttrValueSetItem
        where   dimAttrValueSetItem.DimensionAttributeValueSet   == dimAttrValueSet.RecId
    {
        dimAttrValue        = DimensionAttributeValue::find(dimAttrValueSetItem.DimensionAttributeValue);

        dimAttr             = DimensionAttribute::find(dimAttrValue.DimensionAttribute);

        dimensionValueEntity = DimensionDefaultingControllerBase::findBackingEntityInstance(curext(),dimAttr,dimAttrValue.EntityInstance);

        if (dimAttr.Name == _defaultDimensionName)
        {
            dimNameValue = [dimAttrValue.getValue(), dimAttrValue.getName()];
        }
    }
    return dimNameValue;
}

Tuesday, March 7, 2017

Item CostPrice per dimension Ax2012

Hi guys,

Just a quick code snippet to fetch the CostPrice of an Item based on the dimensions:

public void ale_GetCostPrice()
{
    InventDim       inventDim;
    InventDimParm   inventDimParm;
    InventOnHand    inventOnHand;
    InventSum       inventSum;

    select firstOnly1 ItemId from inventSum
        where inventSum.ItemId == this.ItemId;

    inventDim.InventSiteId = this.inventDim().InventSiteId;
    inventDim.InventLocationId = this.inventDim().InventLocationId;
    inventDim.wMSLocationId = this.inventDim().wMSLocationId;
    inventDim.InventProfileId_RU = this.inventDim().InventProfileId_RU;
    inventDimParm.initFromInventDim(inventDim);

    inventOnHand = InventOnHand::newItemDim(inventSum.ItemId, inventDim, inventDimParm);

    ttsBegin;
    this.CostPrice = inventOnHand.costPricePcs();
    this.inventMovement().journalSetCostPrice();
    this.update();
    ttsCommit;
}

Friday, July 8, 2016

Update ProductDimension, StorageDimension & SearchName of Items/Products

We had a requirement to update ProductDimension and StorageDimension of all the items. I wrote 2 jobs for the same. Below are those:

Update ProductDimension:
static void UpdateProductDimension(Args _args)
{
    EcoResProduct                       ecoResProduct;
    EcoResProductDimensionGroupProduct  ecoResProductDimensionGroupProduct;
 
    while select ecoResProduct
        where ecoResProduct.RecId != 0
    {
        ecoResProductDimensionGroupProduct.initFromProduct(ecoResProduct);
        ecoResProductDimensionGroupProduct.ProductDimensionGroup = 'NameHere';
        ecoResProductDimensionGroupProduct.insert();
    }
 
    info("Done");
}

Update StorageDimension:
static void Job48(Args _args)
{
    EcoResProduct                       ecoResProduct;
    EcoResStorageDimensionGroup         ecoResStorageDimensionGroup;
    EcoResStorageDimensionGroupProduct  ecoResStorageDimensionGroupProduct;
    EcoResStorageDimensionGroupItem     ecoResStorageDimensionGroupItem;
    InventTable                         inventTable;
 
    select Name from ecoResStorageDimensionGroup
        where ecoResStorageDimensionGroup.Name == 'NameHere';
 
    while select ecoResProduct
        join inventTable
        where ecoResProduct.RecId == inventTable.Product
    {
        ecoResStorageDimensionGroupItem.initValue();
        ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.dataAreaId;
        ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
        ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroup.RecId;
        ecoResStorageDimensionGroupItem.insert();
    }
 
    info("Done");
}

Update SearchName:
static void Job48(Args _args)
{
    EcoResProductTranslation    ecoResProductTranslation;
    InventTable                 inventTable;
    EcoResProduct               ecoResProduct;
 
    update_recordset inventTable
    setting NameAlias = ecoResProductTranslation.Name
    join ecoResProduct
    where ecoResProduct.RecId == inventTable.Product
    join ecoResProductTranslation
    where ecoResProductTranslation.Product == ecoResProduct.RecId
    && ecoResProductTranslation.Name == 'Bentinck One Seater Sofa in Provincial Teak Finish with Mudramark';
 
    info("Done");
}

ReferenceSource: http://fandyax.blogspot.in/2013/04/how-to-using-x-create-item-in.html


Thursday, September 10, 2015

Add KPI to Role Center AX2012

It's easy to add KPI/Indicators to the Role Centers but it's a time consuming & tiring task to add multiple KPI/Indicators to the role center. But today I have found out a quick way to do so.

Firstly just add a KPI web part to the role center page.
Go to the Page Definition in AOT, right click on it and click "View Code". Then add a small piece of code just after the ending line of KPI webpart code:

<ArrayOfIndicator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

After the above line add the below given code and change the Cube name & Indicator Name or other required properties of the KPI accordingly. Most importantly change the Id for every KPI.

<Indicator>
    <Id>ae413b36-9f55-40d5-ae21-a8d3ceaa83cc</Id>
    <CubeName>General ledger cube</CubeName>
    <MeasureName>Accounts receivable turnover</MeasureName>
    <DisplayTitle />
    <SliceDimensionAttribute />
    <TimePeriodsName />
    <RolePlayingTimeDimension />
    <ReportPath />
    <ValueType>Amount</ValueType>
    <IsDecreasingBetter>false</IsDecreasingBetter>
    <Visible>true</Visible>
    <IsValid>true</IsValid>
    <EnableFilters>false</EnableFilters>
    <DateFilters>
      <DateFilterItem>
        <DateTimeDimension>Acknowledgement date</DateTimeDimension>
        <TimePeriod>Current_KPI</TimePeriod>
      </DateFilterItem>
    </DateFilters>
    <NonDateFilters />
    <ReportClientMenuItem />
    <ReportWebMenuItem />
    <CompareMeasureName />
    <CompareMeasureCaption />
    <SplitOrder>Top</SplitOrder>
    <NonEmpty>true</NonEmpty>
    <SplitCount>10</SplitCount>
  </Indicator>