Showing posts with label Ax2012. Show all posts
Showing posts with label Ax2012. Show all posts

Monday, January 13, 2014

Thursday, January 2, 2014

How To Iterate all the fields of a table in Ax2012 using x++ code.

In my recent implementation I was having one requirement in this I had to retrieve all the fields of a table and then on certain criteria I had to update these fields in another table. I could do this sing If-else condition but it requires lot of code. So I did it in a better way.

public void updateEstimatesFromCase()
{
    CopyEstimates                   copyEstimates;
    SysDictTable                    dictTable;
    SysDictTable                    caseDictTable;
    SysDictTable                    activityDictTable;
    SysDictField                    dictField;
    SysDictField                    caseDictField;
    SysDictField                    activityDictField;
    FieldId                         fieldId;
    FieldId                         caseFieldId;
    FieldId                         activityFieldId;
    CaseDetailBase                  caseDetailBase = caseDetailBase::find(this.caseId());
    CaseTimeEstimatesTable          caseTimeEstimatesTable;
    ActivityTimeEstimatesTable      activityTimeEstimatesTable;
    ActivityTimeEstimatesTable      buffer;
    ;

    select firstonly caseTimeEstimatesTable
        where caseTimeEstimatesTable.CaseDetailBase == caseDetailBase.RecId;

    select firstOnly activityTimeEstimatesTable
        where activityTimeEstimatesTable.smmActivities == this.smmActivities;

    buf2Buf(buffer,activityTimeEstimatesTable);
    if (activityTimeEstimatesTable.RecId)
    {
        activityTimeEstimatesTable.selectForUpdate(true);
        activityTimeEstimatesTable.update();
    }
    caseDictTable = new SysDictTable(caseTimeEstimatesTable.TableId);
    dictTable = new SysDictTable(this.TableId);
    fieldId = dictTable.fieldNext(0);


    while (fieldId)
    {
        dictField = dictTable.fieldObject(fieldId);
        if (dictField.isSql() && !dictField.isSystem())
        {
            activityTimeEstimatesTable.smmActivities = this.smmActivities;
            if (this.(fieldId) && fieldId != fieldNum(copyEstimates, smmActivities))
            {

                caseFieldId = fieldName2id(tableNum(CaseTimeEstimatesTable),dictField.name());
                activityFieldId = fieldName2id(tableNum(ActivityTimeEstimatesTable),dictField.name());
                activityTimeEstimatesTable.(activityFieldId) = caseTimeEstimatesTable.(caseFieldId);
                if (activityTimeEstimatesTable.RecId)
                {
                    activityTimeEstimatesTable.selectForUpdate(true);
                    activityTimeEstimatesTable.update();
                }
                else
                {
                    activityTimeEstimatesTable.insert();
                }
            }
    }
        fieldId = dictTable.fieldNext(fieldId);
   }
}

Saturday, December 21, 2013

Exchange Rate in Dynamics Ax 2012



·         In Microsoft Dynamics AX, all currencies are provided by default. The currencies are loaded the first time a user opens the General ledger parameters form.
·         Only one currency can represent the Triangulation currency. By default, the EUR currency is selected as the Triangulation currency. To change the Triangulation currency, you must first clear the Reference currency for triangulation check box on the EUR record in the Currencies form. Then, you can select the Reference currency for triangulation on the desired currency.
·         Accounting Currency: This is the monetary unit of measure that is used to record the converted monetary value of economic transactions in ledger accounts. It may also be referred to as the "company" or ledger currency.
·         Reporting Currency: The monetary unit of measure used to record the converted monetary value of economic transactions in ledger accounts for financial and management reporting purposes

·         Create Exchange Rate Types: Exchange rates types are shared data across the entire system and only need to be setup once. Exchange rate types are a grouping that allows different exchange rates for two currencies. Examples include Buy, Sell, Spot, and Budget
·         A currency pair can only exist once and entering a reciprocal pair is not supported in the system. Therefore, if you already have USD to EUR set up, you cannot create a EUR to USD currency pair for the same exchange rate type. The system will calculate the reciprocal rate automatically if it cannot find the exact currency pair during the translation conversion. If you only have USD to EUR set up and you are entering a transaction amount in EUR in a legal entity where USD is the accounting currency, the system will first look for the exact currency pair in the rate type used by the ledger: EUR to USD. If not found, the system will then look for USD to EUR and calculate the reciprocal rate.
·         Display Currency: When you change the display currency, the default currency of a company does not change. Also, this is not a global change; it does not affect any other users in the company, nor does it change the original transaction. It is also meant to be an estimate of the amount in the selected currency.


Friday, December 20, 2013

Dynamics Ax on Cloud


SaaS – Software as a Service
IaaS – Infrastructure as a Service
PaaS – Platform as a Service

Multi-tenant (Serving multiple customers in the same instance of the software)

Today Microsoft Dynamics AX 2009 & 2012 are not designed to be multi-tenant, 100% SaaS offerings.
This applies for Microsoft Dynamics AX 2009 and Microsoft Dynamics AX 2012.

Microsoft does plan to have a total SaaS offering in the future for Microsoft Dynamics AX. Until then, Microsoft Dynamics AX will exist in the Cloud as sitting on top of IaaS, or in a Hybrid cloud mode.

The next release of AX, version 7, will be developed to run on Azure First!
Moving forward to Microsoft Dynamics AX 7.0, it is being developed to run 100% on Microsoft Azure, PaaS offering. It's being developed first, for the cloud, but still the same applies that it can 100% run on-premise.

This flexibility because not everyone wants to run 100% of their total business solution on the cloud, and companies want options.

For some it's all-in, everything, while others, it will be a hyrbid, best of breed for their case mix of SaaS, IaaS & PaaS cloud offerings that makes up their total overall solution.

Thursday, December 19, 2013

How to update sales price for already created sales orders by applying latest trade agreements using x++ code

In one of  implementation project. I got a requirement in this Client wants to update sales orders that were created in past.Requirement was to update sales price by applying new trade agreements that were created later in system after the sales order creation.

I used the following code to update the sales price.

private void updateSalesPrice()
{
    SalesLine                   salesLine;
    PriceDiscPolicyCheckPolicy  checkPolicy;
    str                         text;
    SysOperationProgress        operationProgress;
    boolean                     salesLineFound;
    #AviFiles
    // 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price -->
    Dialog                      dialog;
    DialogField                 dfStartDate;
    DialogText                  dialogText;
    TransDate                   startDate;
    // 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price <-- font="">
    ;

    operationProgress = new SysOperationProgress();
    operationProgress.setCaption("@DTD849");
    operationProgress.setAnimation(#AviUpdate);

    // 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price -->
    dialog = new Dialog("@DTD847");
    dfStartDate = dialog.addField(extendedTypeStr(TransDate), "@DTD1042");
    dfStartDate.value(dateNull());

    text = "@DTD845" + '\n\n' +"@DTD846" ;

    dialogText = dialog.addText(text);
    dialogText.displayHeight(4);
    dialogText.displayLengthValue(50);

    if (dialog.run())
    {
        startDate = dfStartDate.value();
    // 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price <-- font="">
        ttsBegin;
        while select forUpdate salesLine
            where salesLine.SalesType   == SalesType::Sales
            &&    salesLine.SalesStatus <=  SalesStatus::Delivered
            &&   !salesLine.InventTransIdReturn //optimisation dkos 2013-09-25
            &&   (salesLine.ShippingDateRequested >= startDate || startDate == dateNull()) // 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price
        {
            salesLine.ManualEntryChangepolicy = 0;                  //optimisation dkos 2013-09-25
            // 2013-02-18 #20169 csek: Job to update SOprice -->
            salesLine.SystemEntryChangePolicy = 0;                  //optimisation dkos 2013-09-25
            // 2013-02-18 #20169 csek: Job to update SOprice <-- font="">

            checkPolicy = PriceDiscPolicyCheckPolicy::newFromParm(salesLine.PriceDiscResultFields::parmPriceDiscResultFields());
            salesLine.salesPurchLine::resetPriceAgreement();
            salesLine.setPriceAgreement(salesLine.inventDim(), null ,false,true);// 2013-02-07 #20169 csek: Job to update SOprice
            salesLine.LineAmount = salesLine.calcLineAmountForced(salesLine.SalesQty, checkPolicy);
            operationProgress.setText(strFmt("@DTD850",salesLine.SalesId));
            salesLine.update();

            salesLineFound = true;
        }
        ttsCommit;
    }
    if (salesLineFound)
    {
        info("@DTD1041"); // 2013-09-25 #23667_DA0374 dkos: Update Sales Order Unit Price
    }
}

Monday, December 9, 2013

How to create Product master using x++ code

We can create product master using x++ code. I have used below code in one of my implementation.



private void createProductMaster(itemId                        _itemId,
                                 DataAreaId                    _dataAreaId = curext()
                                )
{
    EcoResProductService                    ecoResProdService;
    EcoResEcoResProduct                     ecoResProduct;
    EcoResEcoResProduct_Product_Master      prodMaster;
    EcoResEcoResProduct_Translation         translation;
    EcoResEcoResProduct_Identifier          identifier;
    EcoResEcoResProduct_ProductDimGroup     prodDimGroup;
    EcoResEcoResProduct_StorageDimGroup     storageDimGroup;
    EcoResEcoResProduct_TrackingDimGroup    trackingDimensionGroup;
    InventTable                             localInventTable;
    ;

    if (!this.isProductAlreadyExists() && this.getItemId())
    {
        localInventTable = InventTable::find(_itemId);
        //Initialize the service object
        changeCompany(_dataAreaId)
        {
            ecoResProdService = EcoResProductService::construct();
            ecoResProduct     = new EcoResEcoResProduct();
            prodMaster        = new EcoResEcoResProduct_Product_Master();

            //Newly created and initialize prodMaster

            prodMaster.parmDisplayProductNumber(this.getItemId());
            prodMaster.parmProductType(EcoResProductType::Item);
            prodMaster.parmSearchName(this.getItemId());

            //Create a new translation object:
            Translation = prodMaster.createTranslation().addNew();

            Translation.parmDescription(this.getItemLongDescription());
            Translation.parmLanguageId(CompanyInfo::languageId());
            Translation.parmName(this.getItemShortDescription());
            Identifier = prodMaster.createIdentifier().addNew();

            Identifier.parmProductNumber(this.getItemId());
            if (localInventTable.productDimensionGroup())
            {
                ProdDimGroup = prodMaster.createProductDimGroup().addNew();
                ProdDimGroup.parmProduct(this.getItemId());
                ProdDimGroup.parmProductDimensionGroup(EcoResProductDimensionGroup::find(localInventTable.productDimensionGroup()).Name);
            }

            if (localInventTable.storageDimensionGroup())
            {
                if (EcoResStorageDimensionGroup::find(localInventTable.storageDimensionGroup()).Name)
                {
                    storageDimGroup = prodMaster.createStorageDimGroup().addNew();
                    storageDimGroup.parmProduct(this.getItemId());
                    storageDimGroup.parmStorageDimensionGroup(EcoResStorageDimensionGroup::find(localInventTable.storageDimensionGroup()).Name);
                }
            }

            if (localInventTable.trackingDimensionGroup())
            {
                if (EcoResTrackingDimensionGroup::find(localInventTable.trackingDimensionGroup()).Name)
                {
                    trackingDimensionGroup = prodMaster.createTrackingDimGroup().addNew();
                    trackingDimensionGroup.parmProduct(this.getItemId());
                    trackingDimensionGroup.parmTrackingDimensionGroup(EcoResTrackingDimensionGroup::find(localInventTable.trackingDimensionGroup()).Name);
                }
            }

            prodMaster.parmVariantConfigurationTechnology(EcoResVariantConfigurationTechnologyType::ConstraintBased);
            ecoResProduct.createProduct().add(prodMaster);
            ecoResProdService.create(ecoResProduct);
            }
        }
}

Sunday, December 8, 2013

How to release item using x++code in ax2012

How to release a item in Ax2012 through x++ code. Below code I have used in one of my requirement

public void releaseItem(DataAreaId     _dataAreaId)
{
    EcoResProduct   product;
    InventTable     inventTable;
    ;

    select firstOnly RecID from product
        where product.DisplayProductNumber == this.getItemId();

    if (product.RecId)
    {
        inventTable = inventTable::findByProductInCompany(product.RecId, _dataAreaId);
        if (!inventTable.RecId)
        {
            EcoResProductReleaseManagerBase::releaseProduct(product.RecId,CompanyInfo::findDataArea(_dataAreaId).RecId);
        }
    }

}

How to convert Product master to Product in Ax2012


In One of my implementation I was having a requirement in this I had to convert product master to product across the companies. You can find in below code how we can do this.


public void convertProductMasterToProduct(ItemId    _itemId,
                                          str       _supplyCompany = "",
                                          str       _demandCompany = "")
{
    EcoResProductMaster             master;
    EcoResDistinctProduct           distinctProduct;
    EcoResProductTranslation        productTranslation;
    InventTable                     inventtable;
    EcoResProductIdentifier         productIdentifier;
    str                             text;
    str                             shortText;
    ;

    ttsBegin;

    master = EcoResProductMaster::find(inventtable::find(_itemId).Product, true);

    if (master)
    {
        distinctProduct.clear();
        distinctProduct.initValue();
        distinctProduct.DisplayProductNumber = master.DisplayProductNumber;
        distinctProduct.SearchName = master.SearchName;
        distinctProduct.ProductType = EcoResProductType::Item;
        text = EcoResProductTranslation::findByProductLanguage(master.RecId, CompanyInfo::languageId()).Description;
        shortText = EcoResProductTranslation::findByProductLanguage(master.RecId, CompanyInfo::languageId()).Name;
        master.delete();
        distinctProduct.insert();

       productTranslation.clear();
       productTranslation.initValue();
       productTranslation.LanguageId = CompanyInfo::find().LanguageId;
       productTranslation.Name = shortText;
       productTranslation.Product = distinctProduct.RecId;
       productTranslation.Description = text;
       productTranslation.insert();

       productIdentifier.clear();
       productIdentifier.initValue();
       productIdentifier.ProductNumber = _itemId;
       productIdentifier.Product = distinctProduct.RecId;
       productIdentifier.insert();
        if (_supplyCompany)
        {
            changeCompany(_supplyCompany)
            {
                inventTable = InventTable::find(_itemId, true);
                if (inventtable)
                {
                    InventTable.Product = distinctProduct.RecId;
                    inventtable.StandardConfigId = "";
                    InventTable.update();
                }
            }
        }
        if (_demandCompany)
        {
            changeCompany(_demandCompany)
            {
                inventTable = InventTable::find(_itemId, true);
                if (inventtable)
                {
                    InventTable.Product = distinctProduct.RecId;
                    inventtable.StandardConfigId = "";
                    InventTable.update();

                }
            }
        }
    }
    ttsCommit;


}

Code to call Ax project reverse engineering tool

Code to call Ax project reverse engineering tool
SysVisioAddIn               sysVisioAddIn   = SysVisioAddIn::construct();

sysVisioAddIn.parmModelType(SysVisioModelType::ERModel);
sysVisioAddIn.parmFile(fileName);
sysVisioAddIn.parmUserSelection(SysVisioUserSelection::SharedProject);
sysVisioAddIn.parmProjectNode(SysTreeNode::getSharedProject().AOTfindChild(projectNode.AOTname()));

sysVisioAddIn.run();

Comparison of Layers across AX versions.

Comparison of Layers across AX versions

How to get all the planned orders for a particular demand. in Ax2012

When we create a sales order in Ax. Basically we are creating demand in system and when we run scheduling in system it generates the planned production or purchase orders.


Following is the step by step process.

·         Create sales order. And check the explosion from salesline->Product and supply. Initially there are no planned orders. So there is no record in explosion.



·         Check the explosion from salesline

·         Now run the planning from Master planning ->Periodic->Master scheduling

·         Check the explosion from sales line

·         If we want to get all the planned production orders detail we can get it through following x++ code. We can get top level planned order from REqPo table where on the basis of pegging reference of sales order we can find top level planned production order. We can use that planned order as a parameter in a method and retrieve all the lower level orders.

private void doUpdateReferences(reqPo   _reqPo)
{
    ReqTransExplode         reqTransExplode;
    Map                     mapReqTransLocal;
    MapEnumerator           enumerator;
    container               conMapReqTrans;
    Map                     mapReqTrans;
    reqTrans                reqTrans;
    ReqPO                   reqPo = _reqPo;
    Map                     plannedOrderMap = new Map(Types::Int64, Types::Record);
   
    ;

    while (reqPo)
    {
        if (!plannedOrderMap.exists(reqPo.RecId) )
        {

           reqTransExplode = reqTransExplode::newReqTrans(reqPo.reqTrans(),ReqExplodeType::Down,true);
           reqTransExplode.run();

            conMapReqTrans = reqTransExplode.packMapReqTrans();

mapReqTransLocal    = (conMapReqTrans)  ? Map::create(conMapReqTrans) : new    Map(typeName2Type(extendedtypestr(recId)), Types::Record);

            mapReqTrans = new Map(typeName2Type(extendedtypestr(recId)), Types::Record);
            enumerator = mapReqTransLocal.getEnumerator();
            while(enumerator.moveNext())
            {
                reqTrans = reqTrans::findRecIdCrossCompany(enumerator.currentKey());
                if (reqTrans.RefType == ReqRefType::BOMPlannedOrder)
                {
                    Info(reqtrans.reqpo().refid);
                }
            }
        }

        next reqPo;
    }

}