Monday, December 7, 2020

ADD Lookup, Disable Dialog field using UI builder in D365FO/Ax7


 Hi guys, Today we see how to ADD Lookup, Disable Dialog field using UI builder in D365FO/Ax7.


UiBuilder Class:

class PriceDiscUiBuilder extends             SysOperationAutomaticUIBuilder //SrsReportDataContractUIBuilder

{

    PriceDiscDataContract priceDiscDataContract;

 

    Public void build()

    {

        priceDiscDataContract = this.dataContractObject();

        this.addDialogField(methodStr(PriceDiscDataContract, parmPriceDiscJournalNum), priceDiscDataContract).allowEdit(false);// Disable the field

        this.addDialogField(methodStr(PriceDiscDataContract, parmPostedPriceDiscJournalNum ), priceDiscDataContract);

    }


    Public void lookupPostJour(FormStringControl _formStringControl)

    {

        Query                   query = new Query();

        QueryBuildDataSource    qbds;

        QueryBuildRange         qbr;

        SysTableLookup          lookup;


        lookup = SysTableLookup::newParameters(tableNum(PriceDiscAdmTable), _formStringControl);


        qbds=query.addDataSource(tableNum(PriceDiscAdmTable));

        qbr=qbds.addRange(fieldNum(PriceDiscAdmTable, Posted));

        qbr.value(SysQuery::value(NoYes::Yes));

        lookup.parmQuery(query);


        lookup.addLookupfield(fieldNum(PriceDiscAdmTable, JournalNum));

        lookup.addLookupfield(fieldNum(PriceDiscAdmTable, JournalName));

        lookup.performFormLookup();

    }


    Public void PostBuild()

    {

        DialogField postedJourNum;


        postedJourNum=this.bindInfo().getDialogField(this.dataContractObject(),

                                            methodStr(PriceDiscDataContract,parmPostedPriceDiscJournalNum));

        postedJourNum.registerOverrideMethod(methodStr(FormStringControl, lookup),

                                            methodStr(PriceDiscUiBuilder, lookupPostJour), this);

    }

}


Contract Class:


[DataContractAttribute,

    SysOperationContractProcessingAttribute(classstr(PricediscUiBuilder))]

public class PriceDiscDataContract

{

    str                     priceDiscJournalNum;

    PriceDiscJournalNum     postedPriceDiscJournalNum;

 

    [DataMemberAttribute,

    sysoperationh('Current journal number'),

    SysOperationHelpTextAttribute('Enter journal number')]

//SysOperationControlVisibilityAttribute(false)// Hide control

    public str parmPriceDiscJournalNum(str _priceDiscJournalNum = priceDiscJournalNum)

    {

        priceDiscJournalNum = _priceDiscJournalNum;

        return priceDiscJournalNum;

    }


    [DataMemberAttribute,

    SysOperationLabelAttribute('Posted journal number'),

    SysOperationHelpTextAttribute('Enter journal number')]

    public PriceDiscJournalNum parmPostedPriceDiscJournalNum(PriceDiscJournalNum _priceDiscJournalNum = postedPriceDiscJournalNum)

    {

        postedPriceDiscJournalNum = _priceDiscJournalNum;

        return postedPriceDiscJournalNum;

    }

}

OutPut:

Keep Daxing!!




Display and Edit methods in D365 FO


 Hi guys, Today we see How to add the Display method, Edit method In the standard Table Using COC in D365 FO / AX 7.


Check Below Example:


[ExtensionOf(tableStr(CustGroup))]

final class CustGroup_Extension

{

    [SysClientCacheDataMethod(true)]

    display Name displayName()

    {

        return this.CustGroup + ' ' + this.PaymTermId;

    }


    Edit Name editName(boolean _set, Name _name)

    {

        Name            name    = _name;

        CustDemo        custDemo;

        ;

        if(_set)

        {

            if(name)

            {

                ttsbegin;

                custDemo = CustDemo::find(this.CustGroup,true);

                custDemo.Name  = name;

                custDemo.update();

                ttscommit;

            }

        }

        else

        {

            name    = CustDemo::find(this.CustGroup).Name;

        }

        return name;

    }

}

Create a new field in the grid. Set the data source and data method properties.

Extension methods are not visible using the drop-down,   so you use a special syntax with the style ExtensionClassName::DisplayMethod.

Keep Daxing!!

Adding Code in Standard Table using COC(Chain of command) in AX7/D365fo

 

Hi guys, Today we see how to Add Code in Standard Table using COC in AX7/D365fo.


Check the Below Example.

[ExtensionOf(tableStr(CustGroup))]
Final class CustGroup_Extension
{
    [SysClientCacheDataMethod(true)]
    display Name displayName()
    {
        return this.CustGroup + ' ' + this.PaymTermId;
    }

    void initValue()
    {
        // pre event
        next initValue();
        //Post event

        this.NoYes = NoYes::Yes;
    }

    public void modifiedField(FieldId _fieldId)
    {
        next modifiedField(_fieldId);

        switch (_fieldId)
        {
            case fieldnum(CustGroup, NoYes):
                this.PriceIncludeSalesTax = this.NoYes == NoYes::Yes ? 
                                                NoYes::Yes : NoYes::no;
                break;
        }
    }

    public boolean validateWrite()
    {
        boolean ret = next validateWrite();

        if(!this.TaxGroupId)
        {
            ret = checkFailed('Tax group is mandatory');
        }

        return ret;
    }

    public boolean validateField(FieldId _fieldIdToCheck)
    {
        boolean ret;

        ret = next validateField(_fieldIdToCheck);

        switch (_fieldIdToCheck)
        {
            case fieldnum(CustGroup, Name):
                if (this.NoYes == NoYes::Yes)
                {
                    if(this.Name =="")
                    {
                        ret = ret && checkFailed('when check box is yes
                                this field is mandatory');
                    }
                }
        }

        return ret;
    }
}


Keep Daxing!!

Passing Values to Data contract class in AX7/ D365 fo

 

Hi guys, Today we see how to Pass Values to Data contract class in AX7/ D365 fo.


I am passing the values from 'From Clicked method' to 'Data contract class' by Controller Class. 

Check the below example:


void clicked()

{

    SysOperationController            controller;

    SysOperationDataContract          dataContract;


    controller = new SysOperationController();


    controller.parmLoadFromSysLastValue(false);

    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);

            //controller.getDataContractObject()//// for sys operation     //controller.parmReportContract().parmRdpContract()

    dataContract = controller.getDataContractObject('_contract'); // In service class in processOperation method we are declaring  DataContact as Variable. That variable buffer we have to declare here. Method Signature Ex: public void processOperation(SysOperationDataContract  _contract)


    dataContract.parmCustAccount(CustTable.AccountNum);// passing value


    controller.startOperation();

}

Getting caller Record in Sys Operation Click Here.

Keep Daxing!!

How to Get caller record in SysOperation in AX7/D365 fo

 

Hi guys, Today we see how to Get caller record in Sys operation Controller class in AX7/D365 fo.


Check the below class:


[SysOperationJournaledParametersAttribute(true)]

class DaxPriceDiscController extends SysOperationServiceController

{

    Common                      callerRecord;

    DAXPriceDiscDataContract    daxPriceDiscContract;

    PriceDiscAdmTable           priceDiscAdmTable;

    PriceDiscAdmTrans           priceDiscAdmTrans;


    public Common parmCallerRecord(Common _callerRecord = callerRecord)

    {

        callerRecord = _callerRecord;


        return callerRecord;

    }


    private void initFromCaller()

    {

        daxPriceDiscContract = this.getDataContractObject();


        switch (this.parmCallerRecord().TableId)

        {

            case tableNum(PriceDiscAdmTrans) :

                priceDiscAdmTrans = this.parmCallerRecord() as PriceDiscAdmTrans;


                daxPriceDiscContract.parmPriceDiscJournalNum(priceDiscAdmTrans.journalnum);

            break;

        }

    }


    public static DaxPriceDisccontroller newFromArgs(Args _args)

    {

        IdentifierName                  className;

        IdentifierName                  methodName;

        SysOperationExecutionMode       executionMode;

        DaxPriceDisccontroller          controller;


        [className, methodName, executionMode] = SysOperationServiceController::parseServiceInfo(_args);


        if (_args.record())

        {

            executionMode = SysOperationExecutionMode::Synchronous;

        }

        controller = new DaxPriceDisccontroller(className, methodName, executionMode);

        controller.parmArgs(_args);

        controller.parmCallerRecord(_args.record());


        return controller;

    }


    protected void refreshCallerRecord()

    {

        FormDataSource callerDataSource;

        if (this.parmCallerRecord() && this.parmCallerRecord().dataSource())

        {

            callerDataSource = this.parmCallerRecord().dataSource();

            callerDataSource.research(true);

        }

    }


    void new(IdentifierName _className = classStr(DaxPriceDiscService),

            IdentifierName _methodName = methodStr(DaxPriceDiscService, insertLines),

            SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Synchronous)

    {

        super(_className, _methodName, _executionMode);


        this.parmClassName(classStr(DaxPriceDiscService));

        this.parmMethodName(methodStr(DaxPriceDiscService, insertLines));

    }


    Public static void Main(Args _args)

    {

        DaxPriceDiscController daxPriceDiscController= new DaxPriceDiscController();

        daxPriceDiscController = DaxPriceDiscController::newFromArgs(_args);

        daxPriceDiscController.initFromCaller();

        daxPriceDiscController.refreshCallerRecord();

        daxPriceDiscController.startOperation();

    }


    public DAXPriceDiscDataContract parmDaxPriceDiscContract(DAXPriceDiscDataContract _daxPriceDiscContract = daxPriceDiscContract)

    {

        daxPriceDiscContract = _daxPriceDiscContract;

        return daxPriceDiscContract;

    }

}


Keep Daxing!!

how to write validateField method in Dynamics AX 7, d365

 

Hi guys, Today we see How to write validateField method in Dynamics AX 7, d365.


Check Below class.


class CustTable_Events

{

// Using On Events

    /// <summary>

    ///

    /// </summary>

    /// <param name="sender"></param>

    /// <param name="e"></param>

    [DataEventHandler(tableStr(CustTable), DataEventType::ValidatedField)]

    public static void CustTable_onValidatedField(Common sender, DataEventArgs e)

    {

        ValidateFieldEventArgs event = e as ValidateEventArgs;

        CustTable custTable = sender as CustTable;

    }


// Using Post EventHandler

    /// <summary>

    ///

    /// </summary>

    /// <param name="args"></param>

    [PostHandlerFor(tableStr(CustTable), tableMethodStr(CustTable, validateField))]

    public static void CustTable_Post_validateField(XppPrePostArgs args)

    {

        CustTable custTable     = args.getThis();   //getting table buffer

        FieldId fieldId              = args.getArg("p1"); // Variable buffer

        boolean ret                   = args.getReturnValue(); // get return value from standard method


        switch(fieldId)

        {

            case fieldNum(CustTable, AccountNum):

                if (strLen(custTable.AccountNum) <= 3)

                {

                    ret = ret && checkFailed("Account number should be more than 3 charecters.");

                }

                break;

        }

        args.setReturnValue(ret); // set the return value of this method to standard

    }


Keep Daxing!!

Friday, December 4, 2020

Remove special characters of Date and Time in ax 2012 X++

Hi guys, Today we see how to  Remove special characters of Date and Time in ax 2012 X++.


Run the below job.



 static void FormatDateTimeJob(Args _args)

{

    utcDateTime now = DateTimeUtil::utcNow();


    str formattedOutput;


    now = DateTimeUtil::applyTimeZoneOffset(

    now,

    DateTimeUtil::getClientMachineTimeZone());


    formattedOutput = DateTimeUtil::toFormattedStr(

        now,

        321,

        DateDay::Digits2,

        DateSeparator::None,

        DateMonth::Digits2,

        DateSeparator::None,

        DateYear::Digits2,


        TimeSeparator::Colon,

        TimeSeparator::Colon);


    info(formattedOutput);

    info(strRem(formattedOutput,":"+" "));

}

OutPut:







Keep Daxing!!

Thursday, December 3, 2020

Change LinkType on FormDatasource in AX7 / D365

 

Hi guys, Today we see how to change LinkType on FormDatasource in AX7 / D365.


In this post I change the link type of salesline Table in SalesTable Form without overlayring.

/// <summary>

/// 

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Initialized)]

public static void SalesLine_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)

{      

    sender.queryBuildDataSource().joinMode(joinMode::OuterJoin); 

}

Keep Daxing!!


Get Open Closed Transactions of selected customer in Ax 2012 using x++

 Hi guys, Today we see how to get Open Closed Transactions of selected customer in Ax 2012 using x++.

Run the below job.

static void OpenClosedTransactions(Args _args)

{

    CustTable       custtable;

    CustTrans       custtrans;

    CustTransOpen   custtransopen;

    CustSettlement  custsettlement;


    //OpenTransactions


    while  select custtable

        where custtable.AccountNum == 'US-004'

    join custtrans

        where  custtable.AccountNum == custtrans.AccountNum

    join  custtransopen

        where custtrans.RecId == custtransopen.RefRecId

    {

        info(strfmt('%1,%2,%3,%4,%5',custtable.AccountNum,custtrans.Voucher,custtransopen.AmountCur,custtrans.TransDate,custtransopen.DueDate));

    }


    //ClosedTransactions


    while  select custtable

        where custtable.AccountNum == 'US-004'

    join custtrans

        where  custtable.AccountNum == custtrans.AccountNum

    join  custsettlement

        where custtrans.RecId == custsettlement.TransRecId

    {

        info(strfmt('%1,%2,%3,%4,%5',custtable.AccountNum,custtrans.Voucher,custsettlement.settleAmountCur,custtrans.TransDate,custsettlement.DueDate));

    }


    //sum of open and closed transactions


     while select sum(settleAmountCur) from custsettlement

        where custsettlement.AccountNum == 'US-010'

    {

        info(strfmt('%1',custsettlement.settleAmountCur));

    }



     while select sum(AmountCur) from custtransopen

        where custtransopen.AccountNum == 'US-010'

    {

        info(strfmt('%1',custtransopen.AmountCur));

    }

}

Keep Daxing!!

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!!