Thursday, November 26, 2020

How to create Number sequence Based on selected year in ax 2012 using X++


Hi guys, Today we see how to create a number sequence based on the selected year in ax 2012 using X++.


Here I am using 2 EDT's. Dax Year, New Year. I create a number sequence for that 2 EDT's.

In the setup level I mentioned 2020 for one EDT and for the other I mentioned 2021.


 public void numSeq()

{

    NumberSeq                numberSeq1,numberSeq2;

    TestingMain                testingLoc;


    //str                                    parmNum;

    super();

    testingLoc= element.args().record();

    //select firstOnly testingLocwhere testingLoc.Action==NoYes::Yes;


    if(testingLoc.DaxYear=='2021' && testingLoc.Action==NoYes::Yes)

    {

        numberSeq1 = NumberSeq::newGetNum(NumberSeqReference::findReference(extendedTypeNum(DaxYear)));

        DAXTesting.DaxYear=numberSeq1.num();

        DAXTesting.insert();

    }

    else if(testingLoc.DaxYear=='2020'&& testingLoc.Action==NoYes::Yes)

        {

            numberSeq2 = NumberSeq::newGetNum(NumberSeqReference::findReference(extendedTypeNum(NewYear)));

            testingLoc.NewYear=numberSeq2.num();

            testingLoc.insert();

        }

}

keep Daxing!!

how to get selected records from a form data source using Event handlers of Form in D365/Ax 7.0

 

Hi guys, Today we see how to get selected records from a form data source using Event handlers on Form in D365/Ax 7.0.


Get Current record from form by 'Xformrun':

[formeventhandler(formstr(custgroup), formeventtype::activated)]

    public static void custgroup_onactivated(xformrun sender, formeventargs e)

    {

        custgroup     custgroup;

       // formdatasource ds = sender.datasource(formdatasourcestr(custgroup, custgroup));

       //  custgroup  = ds.cursor();

       //----------OR--------------

       custgroup = sender.datasource(formdatasourcestr(custgroup, custgroup)).cursor();

        info(strfmt('%1', custgroup.custgroup));

    }


Get Current record, FormRun  from form by 'Formdatasource':

[formdatasourceeventhandler(formdatasourcestr(custgroup, custgroup), formdatasourceeventtype::activated)]

    public static void custgroup_onactivated(formdatasource sender, formdatasourceeventargs e)

    {

        custgroup     custgroup;

        // FormRun  formRun = sender.formRun() as FormRun;

        // FormDataSource ds = sender.formrun().datasource('custgroup');

        // ---------------OR------------

        // formdatasource ds = sender.datasource(formdatasourcestr(custgroup, custgroup));

        custgroup = sender.cursor();

       // Button control

       // formRun.design().controlName(formControlStr(Custgroup,Clicked)).enabled(false);

        info(strFmt('%1 - %2 ', custGroup.CustGroup, custGroup.Name));

}


Get Current record from form by 'FormControl' :

[FormControlEventHandler(formControlStr(CustGroup, Clicked), FormControlEventType::Clicked)]

    public static void Clicked_OnClicked(FormControl sender,  FormControlEventArgs e)

    {

       // FormRun  formRun = sender.formRun() as FormRun;

       // formRun.myCustomerMethod();

       CustGroup  custGroup;

       custGroup = sender.formRun().dataSource().cursor();

       info(strFmt('%1 - %2 ', custGroup.CustGroup, custGroup.Name));

    }

Get Current record from form by 'FormDataObject':

{

       CustGroup       custGroup;

        FormDataSource  fds;

        FormDataObject  fd = any2Object(sender) as FormDataObject;

        FormDataSource  fds2 =sender.datasource().formRun().dataSource(2).cursor();

        fds = fd.datasource();

        custGroup = fds.cursor();

        custGroup.Description = custGroup.custGroup +'  '+custGroup.name;

}


Keep Daxing!!

Extensions of Forms using COC in D365 FO/AX 7.0

 Hi guys, Today we see how to Extend the form by COC(chain of command) in D365 FO/ AX 7.0.



Form DataSource Extension:


[ExtensionOf(formDataSourceStr(CustGroup, CustGroup))]

final class CustGroupMy_Extension

{

    public void init()

    {

        CustGroup   custGroup;

        next init();

        while select forupdate custGroup

            where !custGroup.Description

        {

            ttsbegin;

            custGroup.Description = custGroup.CustGroup + ' ' + custGroup.Name;

            custGroup.update();

            ttscommit;

        }

         }

}


Form DataSource Field Extension:


[ExtensionOf(formDataFieldStr(CustGroup, CustGroup, Name))]

public final class CustGroup_Extension

{

    public void modified()

    {

        CustGroup       custGroup;

        FormDataSource  fds;

        FormDataObject  fd = any2Object(this) as FormDataObject;

        next Modified();

        fds = fd.datasource();
        //fds =  element.CustGroup_ds;

        custGroup = fds.cursor();

        custGroup.Description = custGroup.custGroup +' '+custGroup.name;

    }

}


Keep Daxing!!

Wednesday, November 18, 2020

How to prompt a user with a query window in Ax 2012 X++

 

Hi guys, Today we see how to prompt a user with a query window in Ax 2012 using X++.


Run the below job.


static void sysQueryForm(Args _args)

{

    Query               query = new Query();

    QueryRun            queryRun;

    CustomerTable    customerTable;


    query.addDataSource(tablenum(CustomerTable));


    queryRun = new QueryRun(query);


    if(queryRun.prompt())

    {

        while (queryRun.next())

        {

            customerTable = queryRun.get(tablenum(CustomerTable));

            info(strfmt('Item – %1, Name – %2',customerTable.CustId, customerTable.CustName));

        }

    }

      // Filter form data source

    //if (! queryRun.prompt())

    //{

         //element.close();

    //}

//

    //CustomerTable_ds.query(queryRun.query());    

}

We use SysQueryRun also


static void sysQueryForm(Args _args)

{

    Query               query = new Query();

    CustomerTable    customerTable;

    SysQueryRun         queryRunSys;

    ;


    query.addDataSource(tablenum(CustomerTable));

      

    queryRunSys = new SysQueryRun(query);        // use first datasource from  form query

    queryRunSys.promptAllowAddDataSource(false);


    if(queryRunSys.prompt())

    {

        while (queryRunSys.next())

        {

            customerTable = queryRunSys.get(tablenum(CustomerTable));

            info(strfmt('Id – %1, Name – %2',customerTable.CustId, customerTable.CustName));

        }

    }      

}


Keep Daxing!!

Tuesday, November 17, 2020

Create product master, Product dimensions, variants, Product master release, Release Product variants, External product in Ax 2012 X++

 

Hi guys, Today we see how to create Product master, Product dimensions, variants, Product master release, Release Product variants, External product in Ax 2012 using X++.

All operations done in this post.

If you want separate check other posts.

 

static void productMaster(Args _args)

{

    EcoResProductMaster                 ecoResProductMaster;

    EcoResProductDimensionGroupProduct  ecoResProductDimensionGroupProduct;

    EcoResStorageDimensionGroupItem     ecoResStorageDimensionGroupItem;

    EcoResTrackingDimensionGroupItem    ecoResTrackingDimensionGroupItem;

    EcoResProductMasterManager          productMasterManager;

    EcoResProductTranslation            ecoResProductTranslation;

    EcoResConfiguration                 ecoResConfiguration;

    EcoResProductMasterConfiguration    productMasterConfiguration;

    EcoResDistinctProductVariant        ecoResDistinctProductVariant;

    InventDim                           inventDim;

    InventDimCombination                inventDimCombination;

    custVendExternalItem                custVendExternalItem,custVendExternalItemLoc;

    EcoResProductReleaseSessionManager  ecoResProductReleaseSessionManager;

    InventTable                         inventTable,inventTableLoc;

    InventItemSetupSupplyType           inventItemSetupSupplyType;

    InventModelGroupItem                inventModelGroupItem,inventModelGroupItemLoc;

    InventItemGroupItem                 inventItemGroupItem,inventItemGroupItemLoc;

    WHSReservationHierarchyItem         wHSReservationHierarchyItem,wHSReservationHierarchyItemLoc;

    RefRecId                            _productMasterRecId,_oldproductMasterRecId;

    Name                                id,_name="DX";

    container                           con,dimensionValues;

    int                                 i=1;


    

    _oldproductMasterRecId = 22565432486;

    

    // Product master creation

    ecoResProductMaster = EcoResProductMaster::find(_oldproductMasterRecId);

    if (ecoResProductMaster)

    {

        inventTable = InventTable::findByProduct(ecoResProductMaster.RecId);


        ecoResProductDimensionGroupProduct = EcoResProductDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);

        ecoResStorageDimensionGroupItem  = EcoResStorageDimensionGroupItem::findByItem(inventTable.dataAreaId,inventTable.ItemId);

        ecoResTrackingDimensionGroupItem = EcoResTrackingDimensionGroupItem::findByItem(inventTable.dataAreaId,inventTable.ItemId);


        productMasterManager = EcoResProductMasterManager::construct();


        _productMasterRecId = productMasterManager.createProductMaster(

                                                    _name + ecoResProductMaster.DisplayProductNumber,

                                                    ecoResProductMaster.SearchName,

                                                    ecoResProductMaster.ProductType,

                                                    ecoResProductMaster.VariantConfigurationTechnology,

                                                    ecoResProductDimensionGroupProduct.ProductDimensionGroup,

                                                    ecoResStorageDimensionGroupItem.StorageDimensionGroup,

                                                    ecoResTrackingDimensionGroupItem.TrackingDimensionGroup);


        select firstOnly Name, Description from ecoResProductTranslation

            where ecoResProductTranslation.Product == ecoResProductMaster.RecId;


        EcoResProductTranslation::createOrUpdateTranslation(_productMasterRecId, ecoResProductTranslation.Name, ecoResProductTranslation.Description);

    }

    

    info(strFmt('%1',EcoResProductMaster::find(_productMasterRecId).DisplayProductNumber));

    

    // create variants

    con = ['1004','1005','1006'];

      ecoresproductmaster = ecoresproductmaster::find(_productmasterrecid);

        if (ecoresproductmaster)

        {

            for (i=1 ; i<=conlen(con) ; i++)

            {

                ecoresconfiguration = ecoresconfiguration::findbyname(conpeek(con, i));

                if (!ecoresconfiguration)

                {

                    ecoresconfiguration.clear();

                    ecoresconfiguration.initvalue();

                    ecoresconfiguration.name = conpeek(con,i);

                    ecoresconfiguration.insert();

                }


                select firstonly recid from inventdim

                    where inventdim.configid == ecoresconfiguration.name;

                if (!inventdim.recid)

                {

                    inventdim.clear();

                    inventdim.configid  = ecoresconfiguration.name;

                    inventdim           = inventdim::create(inventdim);

                }


                productmasterconfiguration = ecoresproductmasterconfiguration::find(ecoresproductmaster.recid,ecoresconfiguration.recid);


                if (!productmasterconfiguration)

                {

                    productmasterconfiguration.clear();

                    productmasterconfiguration.initvalue();

                    productmasterconfiguration.configproductmaster              = ecoresproductmaster.recid;

                    productmasterconfiguration.configuration                    = ecoresconfiguration.recid;

                    productmasterconfiguration.configproductdimensionattribute  = ecoresproductdimensionattribute::inventdimfieldid2dimensionattributerecid(fieldnum(inventdim, configid));


                    productmasterconfiguration.insert();

                }


                dimensionvalues              = ecoresproductvariantdimvalue::getdimensionvaluescontainer(ecoresconfiguration.name);

                ecoresdistinctproductvariant = ecoresproductvariantmanager::finddistinctproductvariant(ecoresproductmaster.recid,dimensionvalues);


                if (!ecoresdistinctproductvariant)

                {

                    ecoresproductvariantmanager::createproductvariant(ecoresproductmaster.recid,

                                                                    ecoresproduct::find(ecoresproductmaster.recid).searchname + ecoresconfiguration.name,

                                                                    dimensionvalues);

                }

            }

    }

        //release product master

        ecoResProductReleaseSessionManager = EcoResProductReleaseSessionManager::newReleaseSession();


        ecoResProductReleaseSessionManager.addProductMasterWithVariants(_productMasterRecId);

        ecoResProductReleaseSessionManager.addLegalEntityForAllProducts(CompanyInfo::findDataArea(curext()).RecId);


        if(ecoResProductReleaseSessionManager.execute())

        {

            inventTable     = InventTable::findByProduct(_productMasterRecId,true);

            inventTableLoc     = InventTable::findByProduct(_oldProductMasterRecId,true);


            if (inventTable)

            {

                ttsBegin;


                inventItemSetupSupplyType     = InventItemSetupSupplyType::find(inventTable.ItemId,curext(),true);


                if (inventItemSetupSupplyType)

                {

                    inventItemSetupSupplyType.DefaultOrderType = ReqPOType::Production;

                    inventItemSetupSupplyType.update();

                }

                ttsCommit;


                inventModelGroupItemLoc = InventModelGroupItem::findByItemIdLegalEntity(inventTableLoc.ItemId,curext());


                inventModelGroupItem.clear();

                inventModelGroupItem.initValue();

                inventModelGroupItem.ItemDataAreaId         = inventTable.dataAreaId;

                inventModelGroupItem.ItemId                 = inventTable.ItemId;

                inventModelGroupItem.ModelGroupId           = inventModelGroupItemLoc.ModelGroupId;

                inventModelGroupItem.ModelGroupDataAreaId   = curext();

                inventModelGroupItem.insert();


                inventItemGroupItemLoc = InventItemGroupItem::findByItemIdLegalEntity(inventTableLoc.ItemId,curext());


                inventItemGroupItem.clear();

                inventItemGroupItem.initValue();

                inventItemGroupItem.ItemDataAreaId      = inventTable.dataAreaId;

                inventItemGroupItem.ItemId              = inventTable.ItemId;

                inventItemGroupItem.ItemGroupId         = inventItemGroupItemLoc.ItemGroupId;

                inventItemGroupItem.ItemGroupDataAreaId = curext();

                inventItemGroupItem.insert();


                wHSReservationHierarchyItemLoc = WHSReservationHierarchyItem::findByItem(curext(),inventTableLoc.ItemId);


                wHSReservationHierarchyItem.clear();

                wHSReservationHierarchyItem.initValue();

                wHSReservationHierarchyItem.ReservationHierarchy = wHSReservationHierarchyItemLoc.ReservationHierarchy;

                wHSReservationHierarchyItem.ItemId               = inventTable.ItemId;

                wHSReservationHierarchyItem.ItemDataAreaId       = inventTable.dataAreaId;

                wHSReservationHierarchyItem.insert();

            }

            info('Product released');

    }


    //External product creation

    inventTable = InventTable::findByProduct(_productMasterRecId);


    select firstOnly InventDimId, ItemId from inventDimCombination

        where inventDimCombination.ItemId == inventTable.ItemId;


    inventDim = InventDim::find(inventDimCombination.InventDimId);


    select firstOnly custVendExternalItemLoc

        where custVendExternalItemLoc.ItemId == inventTable.ItemId;


    custVendExternalItem.clear();

    custVendExternalItem.initValue();

    custVendExternalItem.ItemId             = inventDimCombination.ItemId;

    custVendExternalItem.ExternalItemId     = inventTable.ItemId;

    custVendExternalItem.ModuleType         = ModuleInventPurchSalesVendCustGroup::CustGroup;

    custVendExternalItem.CustVendRelation   = '01';

    custVendExternalItem.ExternalItemTxt    = inventTable.itemName();

    custVendExternalItem.Description        = inventTable.itemName();

    custVendExternalItem.InventDimId        = inventDim.inventDimId;

    custVendExternalItem.insert();

    info('externalProuct created');


    

    // release variants to released product

    //EcoResProductReleaseManagerBase     releaseManager;

    //EcoResProductMaster                 ecoResProductMaster;

    //EcoResDistinctProductVariant        ecoResDistinctProductVariant;

    //Name                                configId;

    //container                           con,dimensionvalues;

    //int                                 i=1;

    //RefRecId                            _productMasterRecId;

    //

    //con = ['1004','1005','1006'];

    //_productMasterRecId = 52565460661;

    //ecoResProductMaster = EcoResProductMaster::find(_productMasterRecId);

        //for (i=1 ; i<=conLen(con) ; i++)

        //{

            //configId = conPeek(con,i);

//

            //select firstOnly ecoResDistinctProductVariant

                //where ecoResDistinctProductVariant.ProductMaster == ecoResProductMaster.RecId

                   //&& ecoResDistinctProductVariant.DisplayProductNumber == EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(ecoResProductMaster.productNumber(),

                                                                                                         //EcoResProductVariantDimValue::getDimensionValuesContainer(configId));

            //if (ecoResDistinctProductVariant && !ecoResDistinctProductVariant.isReleased())

            //{

                //releaseManager = EcoResProductReleaseManagerBase::newFromProduct(ecoResDistinctProductVariant);

                //releaseManager.release();

            //}

        //}

        //info('Product variants released');


}

Keep Daxing!!

Create External Item for Product master in Ax 2012 using X++

 Hi guys, Today we see how to create New external Item for Product master in Ax 2012 using X++.

static void externalProduct(Args _args)

{

    InventTable                 inventTable;

    InventDim                   inventDim;

    InventDimCombination        inventDimCombination;

    custVendExternalItem        custVendExternalItem,custVendExternalItemLoc;

    RefRecId                    _productMasterRecId = 52565460661;

    

        inventTable = InventTable::findByProduct(_productMasterRecId);


        select firstOnly InventDimId, ItemId from inventDimCombination

            where inventDimCombination.ItemId == inventTable.ItemId;


        inventDim = InventDim::find(inventDimCombination.InventDimId);


        select firstOnly custVendExternalItemLoc

            where custVendExternalItemLoc.ItemId == inventTable.ItemId;


        custVendExternalItem.clear();

        custVendExternalItem.initValue();

        custVendExternalItem.ItemId             = inventDimCombination.ItemId;

        custVendExternalItem.ExternalItemId     = inventTable.ItemId;

        custVendExternalItem.ModuleType         = ModuleInventPurchSalesVendCustGroup::CustGroup;

        custVendExternalItem.CustVendRelation   = '01';

        custVendExternalItem.ExternalItemTxt    = inventTable.itemName();

        custVendExternalItem.Description        = inventTable.itemName();

        custVendExternalItem.InventDimId        = inventDim.inventDimId;

        custVendExternalItem.insert();

        info('externalProuct created');

}

Keep Daxing!!

Release Product variants to Released products in ax 2012 using X++

 Hi guys, Today we see how to release product variants in ax 2012 using X++.


static void releaseProductVariantsToReleasedProduct(Args _args)

{

     EcoResProductReleaseManagerBase     releaseManager;

    EcoResProductMaster                 ecoResProductMaster;

    EcoResDistinctProductVariant        ecoResDistinctProductVariant;

    Name                                configId;

    container                           con,dimensionvalues;

    int                                 i=1;

    RefRecId                            _productMasterRecId;

    

    con = ['1004','1005','1006'];

    _productMasterRecId = 52565460661;

    ecoResProductMaster = EcoResProductMaster::find(_productMasterRecId);

        for (i=1 ; i<=conLen(con) ; i++)

        {

            configId = conPeek(con,i);


            select firstOnly ecoResDistinctProductVariant

                where ecoResDistinctProductVariant.ProductMaster == ecoResProductMaster.RecId

                   && ecoResDistinctProductVariant.DisplayProductNumber == EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(ecoResProductMaster.productNumber(),

                                                                                                         EcoResProductVariantDimValue::getDimensionValuesContainer(configId));

            if (ecoResDistinctProductVariant && !ecoResDistinctProductVariant.isReleased())

            {

                releaseManager = EcoResProductReleaseManagerBase::newFromProduct(ecoResDistinctProductVariant);

                releaseManager.release();

            }

        }

        info('Product variants released');

}

Create Product master Dimensions and Variants in Ax 2012 using X++

Click Here


Keep Daxing!!

Release Product master from other Product master details in ax 2012 using X++


 Hi guys, Today we see how to Release product master from other product details in ax 2012 using X++.


Run the below job.

static void productMaterRelease(Args _args)

{

    EcoResProductReleaseSessionManager      ecoResProductReleaseSessionManager;

    InventTable                             inventTable,inventTableLoc;

    InventItemSetupSupplyType               inventItemSetupSupplyType;

    InventModelGroupItem                    inventModelGroupItem,inventModelGroupItemLoc;

    RefRecId                                _productMasterRecId,_oldProductMasterRecId;

    InventItemGroupItem                     inventItemGroupItem,inventItemGroupItemLoc;

    WHSReservationHierarchyItem             wHSReservationHierarchyItem,wHSReservationHierarchyItemLoc;

    

    _productMasterRecId = 52565460661;

    _oldProductMasterRecId = 22565432486;

       ecoResProductReleaseSessionManager = EcoResProductReleaseSessionManager::newReleaseSession();


        ecoResProductReleaseSessionManager.addProductMasterWithVariants(_productMasterRecId);

        ecoResProductReleaseSessionManager.addLegalEntityForAllProducts(CompanyInfo::findDataArea(curext()).RecId);


        if(ecoResProductReleaseSessionManager.execute())

        {

            inventTable     = InventTable::findByProduct(_productMasterRecId,true);

            inventTableLoc     = InventTable::findByProduct(_oldProductMasterRecId,true);


            if (inventTable)

            {

                ttsBegin;


                inventItemSetupSupplyType     = InventItemSetupSupplyType::find(inventTable.ItemId,curext(),true);


                if (inventItemSetupSupplyType)

                {

                    inventItemSetupSupplyType.DefaultOrderType = ReqPOType::Production;

                    inventItemSetupSupplyType.update();

                }

                ttsCommit;


                inventModelGroupItemLoc = InventModelGroupItem::findByItemIdLegalEntity(inventTableLoc.ItemId,curext());


                inventModelGroupItem.clear();

                inventModelGroupItem.initValue();

                inventModelGroupItem.ItemDataAreaId         = inventTable.dataAreaId;

                inventModelGroupItem.ItemId                 = inventTable.ItemId;

                inventModelGroupItem.ModelGroupId           = inventModelGroupItemLoc.ModelGroupId;

                inventModelGroupItem.ModelGroupDataAreaId   = curext();

                inventModelGroupItem.insert();


                inventItemGroupItemLoc = InventItemGroupItem::findByItemIdLegalEntity(inventTableLoc.ItemId,curext());


                inventItemGroupItem.clear();

                inventItemGroupItem.initValue();

                inventItemGroupItem.ItemDataAreaId      = inventTable.dataAreaId;

                inventItemGroupItem.ItemId              = inventTable.ItemId;

                inventItemGroupItem.ItemGroupId         = inventItemGroupItemLoc.ItemGroupId;

                inventItemGroupItem.ItemGroupDataAreaId = curext();

                inventItemGroupItem.insert();


                wHSReservationHierarchyItemLoc = WHSReservationHierarchyItem::findByItem(curext(),inventTableLoc.ItemId);


                wHSReservationHierarchyItem.clear();

                wHSReservationHierarchyItem.initValue();

                wHSReservationHierarchyItem.ReservationHierarchy = wHSReservationHierarchyItemLoc.ReservationHierarchy;

                wHSReservationHierarchyItem.ItemId               = inventTable.ItemId;

                wHSReservationHierarchyItem.ItemDataAreaId       = inventTable.dataAreaId;

                wHSReservationHierarchyItem.insert();

            }

            info('Product released');

    }

}

Keep Daxing!!

Release Product master through class in ax 2012 using X++

 Hi guys, Today we see how to release Product master through class in ax 2012 using X++.


static void productMasterRelease(Args _args)

{

    EcoResProductReleaseSessionManager      ecoResProductReleaseSessionManager;

    RefRecId                                _productMasterRecId = 52565460661;


       ecoResProductReleaseSessionManager = EcoResProductReleaseSessionManager::newReleaseSession();


        ecoResProductReleaseSessionManager.addProductMasterWithVariants(_productMasterRecId);

        ecoResProductReleaseSessionManager.addLegalEntityForAllProducts(CompanyInfo::findDataArea(curext()).RecId);

ecoResProductReleaseSessionManager.execute();

}

Keep Daxing!!

Create Product master Dimensions and Variants in Ax 2012 using X++

 Hi guys, Today we see how to create product master dimensions and variants in ax 2012 using X++.


Run the below job.


static void createDimesionsAndVariants(Args _args)

{

    EcoResProductMaster                 ecoResProductMaster;

    EcoResConfiguration                 ecoResConfiguration;

    EcoResProductMasterConfiguration    productMasterConfiguration;

    EcoResDistinctProductVariant        ecoResDistinctProductVariant;

    InventDim                           inventDim;

    RefRecId                            _productMasterRecId;

    container                           con,dimensionValues;

    int                                 i=1;

    

    con = ['1001','1002','1003'];

    _productMasterRecId = 52565460661;

      ecoResProductMaster = EcoResProductMaster::find(_productMasterRecId);

        if (ecoResProductMaster)

        {

            for (i=1 ; i<=conLen(con) ; i++)

            {

                ecoResConfiguration = EcoResConfiguration::findByName(conPeek(con, i));

                if (!ecoResConfiguration)

                {

                    ecoResConfiguration.clear();

                    ecoResConfiguration.initValue();

                    ecoResConfiguration.Name = conPeek(con,i);

                    ecoResConfiguration.insert();

                }


                select firstOnly RecId from inventDim

                    where inventDim.configId == ecoResConfiguration.Name;

                if (!inventDim.RecId)

                {

                    inventDim.clear();

                    inventDim.ConfigId  = ecoResConfiguration.Name;

                    inventDim           = InventDim::create(inventDim);

                }


                productMasterConfiguration = EcoResProductMasterConfiguration::find(ecoResProductMaster.RecId,ecoResConfiguration.RecId);


                if (!productMasterConfiguration)

                {

                    productMasterConfiguration.clear();

                    productMasterConfiguration.initValue();

                    productMasterConfiguration.ConfigProductMaster              = ecoResProductMaster.RecId;

                    productMasterConfiguration.Configuration                    = ecoResConfiguration.RecId;

                    productMasterConfiguration.ConfigProductDimensionAttribute  = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));


                    productMasterConfiguration.insert();

                }


                dimensionValues              = EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name);

                ecoResDistinctProductVariant = EcoResProductVariantManager::findDistinctProductVariant(ecoResProductMaster.RecId,dimensionValues);


                if (!ecoResDistinctProductVariant)

                {

                    EcoResProductVariantManager::createProductVariant(ecoResProductMaster.RecId,

                                                                    EcoResProduct::find(ecoResProductMaster.RecId).SearchName + ecoResConfiguration.Name,

                                                                    dimensionValues);

                }

            }

    }

}


Keep Daxing!!

Create product master from other product details through class in ax 2012 using X++.

 

Hi guys, Today we see how to create Product master from other product details through class in ax 2012 using X++.


Run the below job.

static void productMasterCreation(Args _args)

{

    EcoResProductMaster                 ecoResProductMaster;

    InventTable                         inventTable;

    RefRecId                            _oldproductMasterRecId,productMasterRecId;

    EcoResProductDimensionGroupProduct  ecoResProductDimensionGroupProduct;

    EcoResStorageDimensionGroupItem     ecoResStorageDimensionGroupItem;

    EcoResTrackingDimensionGroupItem    ecoResTrackingDimensionGroupItem;

    EcoResProductMasterManager          productMasterManager;

    EcoResProductTranslation            ecoResProductTranslation;

    Name                                id,_name="AX";

    _oldproductMasterRecId = 22565432486;

    ecoResProductMaster = EcoResProductMaster::find(_oldproductMasterRecId);

    if (ecoResProductMaster)

    {


    inventTable = InventTable::findByProduct(ecoResProductMaster.RecId);


    ecoResProductDimensionGroupProduct = EcoResProductDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);

    ecoResStorageDimensionGroupItem  = EcoResStorageDimensionGroupItem::findByItem(inventTable.dataAreaId,inventTable.ItemId);

    ecoResTrackingDimensionGroupItem = EcoResTrackingDimensionGroupItem::findByItem(inventTable.dataAreaId,inventTable.ItemId);


    productMasterManager = EcoResProductMasterManager::construct();


    productMasterRecId = productMasterManager.createProductMaster(

                                                _name + ecoResProductMaster.DisplayProductNumber,

                                                ecoResProductMaster.SearchName,

                                                ecoResProductMaster.ProductType,

                                                ecoResProductMaster.VariantConfigurationTechnology,

                                                ecoResProductDimensionGroupProduct.ProductDimensionGroup,

                                                ecoResStorageDimensionGroupItem.StorageDimensionGroup,

                                                ecoResTrackingDimensionGroupItem.TrackingDimensionGroup);


    select firstOnly Name, Description from ecoResProductTranslation

        where ecoResProductTranslation.Product == ecoResProductMaster.RecId;


    EcoResProductTranslation::createOrUpdateTranslation(productMasterRecId, ecoResProductTranslation.Name, ecoResProductTranslation.Description);

    }

    

    info(strFmt('%1',EcoResProductMaster::find(productMasterRecId).DisplayProductNumber));

}

Keep Daxing!!

How to delete Product master dimensions in ax 2012 using X++.

 Hi guys, Today we see how to delete product master dimensions in ax 2012 using X++. Just run the below job.


static void deleteProductDimensions(ItemId _itemId, ConfigName _processId) { EcoResConfiguration ecoResConfiguration; EcoResProductMaster ecoResProductMaster; EcoResDistinctProductVariant ecoResDistinctProductVariant; EcoResProductMasterConfiguration productMasterConfiguration; if (_itemId && _processId) { select firstOnly DisplayProductNumber from ecoResProductMaster where ecoResProductMaster.DisplayProductNumber == _itemId; if (ecoResProductMaster.DisplayProductNumber) { ecoResConfiguration = EcoResConfiguration::findByName(_processId); if (ecoResConfiguration) { delete_from ecoResDistinctProductVariant where ecoResDistinctProductVariant.ProductMaster == ecoResProductMaster.RecId && ecoResDistinctProductVariant.DisplayProductNumber == EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions( ecoResProductMaster.DisplayProductNumber, EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name)); delete_from productMasterConfiguration where productMasterConfiguration.ConfigProductMaster == ecoResProductMaster.RecId && productMasterConfiguration.Configuration ==ecoResConfiguration.recid; } } } } }

Keep Daxing !!

Tuesday, November 10, 2020

How to filter Product and Product master Details separately in Ax 2012 X++

 

Hi guys, Today we see how to filter Product and ProductMaster details separately in ax 2012 using X++.

check this class you can find the code in below method.

\Classes\EcoResProductListPageInteraction\initializeQuery


Run the below job:


static void filterProductdetails(Args _args)

{

    ProdParameters          prodParameters;

    Query                   query = new Query();

    QueryBuildDataSource    qbds1,qbds2;

    QueryBuildRange         queryBuildRange;

    QueryBuildLink          queryBuildLink;

    Range                   range;

    QueryRun                queryrun;

    EcoResProduct           ecoResProduct;


    InventTable             inventTable;

    

    //select firstOnly prodParameters;


    qbds1 = query.addDataSource(tablenum(InventTable));

    //queryBuildRange = qbds1.addRange(fieldnum(InventTable, Product));

    //queryBuildRange.value(prodParameters.Product);

    

    // Add the second datasource to the first data source

    qbds2 = qbds1.addDataSource(tablenum(EcoResProduct));

    queryBuildLink = qbds2.addLink(fieldnum(InventTable, product),fieldnum(EcoResProduct, RecId));


// Get only ProductMaster details

    //range = queryValue(DictTable::getRelationTypeFromTableName(tableStr(EcoResProductMaster)));


// Get only Product details

    range = queryValue(DictTable::getRelationTypeFromTableName(tableStr(EcoResDistinctProduct)));


// Get both Product and ProductMaster details

    //range = queryValue(DictTable::getRelationTypeFromTableName(tableStr(EcoResProductMaster)));

    //range = queryRangeConcat(range, DictTable::getRelationTypeFromTableName(tableStr(EcoResDistinctProduct)));

    

    query.dataSourceName(queryDataSourceStr(EcoResProductListPage, EcoResProduct));

    queryBuildRange = qbds2.addRange(fieldNum(EcoResProduct, InstanceRelationType));

    queryBuildRange.value(range);


    queryrun    = new queryrun(query);

    while(queryrun.next())

    {

    inventTable   = queryrun.get(tablenum(InventTable));

    ecoResProduct = queryrun.get(tablenum(EcoResProduct));

    info(strfmt("%1 - %2  ",inventTable.ItemId,ecoResProduct.productSubtype())); // to check your result

    }

}

OutPut:



Keep Daxing!!

Sunday, November 1, 2020

How to get Date or Time from UTCDateTime in ax 2012 using X+

 

Hi guys, Today we see how to get date or Time from UTCDateTime in ax 2012 using X++. 


Run the below job.


static void dateFunctions(Args _args)

{

    CustTable       custable;

    int             daysdiff;

    Date            _Currentdate;

    utcDateTime     _UtcStartPeriod;

    utcDateTime     _UtcEndPeriod;

    utcDateTime     dateTime;

    date            dateInUserTimeZone;

    TimeOfDay       timeInUserTimeZone;

    AccountNum      _accountNum = '456';

    

    select custable where custable.AccountNum == _accountNum;

    

    // Convert normal date into utcDateTime

    _currentdate=today();

   _UtcStartPeriod =  DateTimeUtil::newDateTime(_currentdate,0);


    // Convert utcDateTime into Date

    dateInUserTimeZone = DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(custable.modifiedDateTime, DateTimeUtil::getUserPreferredTimeZone()));

    timeInUserTimeZone = DateTimeUtil::time(DateTimeUtil::applyTimeZoneOffset(custable.modifiedDateTime, DateTimeUtil::getUserPreferredTimeZone()));

    //dateTime = DateTimeUtil::newDateTime(dateInUserTimeZone, timeInUserTimeZone, DateTimeUtil::getUserPreferredTimeZone());

    

    daysDiff =  dateInUserTimeZone - today();


    info(strfmt("today date - %1",today()));

    info(strfmt("cust account date - %1",dateInUserTimeZone));

    info(strfmt("cust account time - %1",timeInUserTimeZone));


    info(strfmt("days difference - %1",daysDiff));

}

Output:





Keep Daxing!!

Import General Journals through Excel in AX 2012 X++


 Hi guys, Today we see how to Import General Journals through Excel in Ax 2012 using Excel.


Run the below job.

static void JournalImport(Args _args)

{

    Dialog                  _dialog;

    DialogField             _file;

    SysExcelApplication     application;

    SysExcelWorkbooks       workbooks;

    SysExcelWorkbook        workbook;

    SysExcelWorksheets      worksheets;

    SysExcelWorksheet       worksheet;

    SysExcelCells           cells;

    COMVariantType          type;

    Name                    name;

    FileName                filename;

    LedgerJournalACType     LedgerJournalACType;



    AxLedgerJournalTable    axLedgerJournalTable ;

    AxLedgerJournalTrans    axLedgerJournalTrans;


    container               accPattern,offSetPattern;

    int                     row = 1;


    str                     _Name;

    str                     _Description;

    AmountCurDebit          _Debit;

    str                     _LedgerDimension;

    str                     _OffsetAccountType;

    str                     _AccountType;

    str                     _OffsetLedgerDimension;



    axLedgerJournalTable = new AxLedgerJournalTable();


    axLedgerJournalTrans = new AxLedgerJournalTrans();


    _dialog = new Dialog("Import Data From Excel");

    _dialog.addText("Select file:");


    _file   = _dialog.addField(ExtendedTypeStr("FilenameOpen"));

    _dialog.run();


    if (_dialog.closedOK())

    {


        info(_file.value() );


    application = SysExcelApplication::construct();

    workbooks   = application.workbooks();

    //specify the file path that you want to read

    filename   =_file.value(); //ExcelSheet File Name

    try

    {

        workbooks.open(filename);

    }

    catch (Exception::Error)

    {

         throw error('File cannot be opened');

    }


    workbook    = workbooks.item(1);

    worksheets  = workbook.worksheets();

    worksheet   = worksheets.itemFromNum(1); //Here 1 is the worksheet Number

    cells       = worksheet.cells();

    do

    {

        row++;

        _Name                       = cells.item(row, 1).value().bStr();

        _Description                = cells.item(row, 2).value().bStr();

        _Debit                      = cells.item(row, 3).value().double();

        _OffsetAccountType          = cells.item(row, 5).value().bStr();

        _AccountType                = cells.item(row, 6).value().bStr();



        axLedgerJournalTable.parmJournalName(_Name);


        axLedgerJournalTable.save();


        axLedgerJournalTrans.parmJournalNum(axLedgerJournalTable.ledgerJournalTable().JournalNum);


        axLedgerJournalTrans.parmTransDate(systemDateGet());

        axLedgerJournalTrans.parmCurrencyCode('USD');

        axLedgerJournalTrans.parmTxt(_Description);

        axLedgerJournalTrans.parmAmountCurDebit(_Debit);

        axLedgerJournalTrans.parmExchRate(Currency::exchRate('USD'));

        axLedgerJournalTrans.parmAccountType(str2enum(LedgerJournalACType,_AccountType));



        accPattern = ['110110','110110',2,'BusinessUnit',"001","Department","022"];

        axLedgerJournalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accPattern));



        offSetPattern = ['112140',"112140",2,'BusinessUnit','003',"Department","024"];

        axLedgerJournalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offSetPattern));


        axLedgerJournalTrans.save();


        type = cells.item(row+1, 1).value().variantType();

    }


        while (type != COMVariantType::VT_EMPTY);

        application.quit();

        info(strFmt("Journal %1 created", axLedgerJournalTable.ledgerJournalTable().JournalNum));

        info("Data is Imported");

    }

    }


Keep Daxing!!

How to Create a General Journal line in D365 FO or Ax 2012 using X++

 

Hi guys, Today we see how to create General Journal line in Ax 2012 or D365 FO.


Here we are using 2 classes.


    AxLedgerJournalTable    axLedgerJournalTable ;

    AxLedgerJournalTrans    axLedgerJournalTrans;


        axLedgerJournalTable.parmJournalName(_Name);

        axLedgerJournalTable.save();


       axLedgerJournalTrans.parmJournalNum(axLedgerJournalTable.ledgerJournalTable().JournalNum);

        axLedgerJournalTrans.parmTransDate(systemDateGet());

        axLedgerJournalTrans.parmCurrencyCode('USD');

        axLedgerJournalTrans.parmTxt(_Description);

        axLedgerJournalTrans.parmAmountCurDebit(_Debit);

        axLedgerJournalTrans.parmExchRate(Currency::exchRate('USD'));

        axLedgerJournalTrans.parmAccountType(str2enum(LedgerJournalACType,_AccountType));

        accPattern = ['110110','110110',2,'BusinessUnit',"001","Department","022"];

        axLedgerJournalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accPattern));

        offSetPattern = ['112140',"112140",2,'BusinessUnit','003',"Department","024"];

        axLedgerJournalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offSetPattern));


        axLedgerJournalTrans.save();


Keep Daxing!!