Wednesday, 30 December 2015

short cut hot keys in ax 2012

say if we want a particular alphabet to be made as short cut for a functionality when we press alt :

we can achieve this by design

go to action pane button and button properties

"key tips" : select a label for a alphabet like A, B ,C and save the change now your short cut key is ready...

Tuesday, 29 December 2015

post PO by code in ax 2012


please find the code for posting PO here the code is some what lengthy it is doing some other functionality too.

public void InvoicePO(PurchTable _purchTable)
{
    PurchTable                      purchTable,purchTableCurr;
    int                             seq;
    PurchFormLetter_PackingSlip     packingSlip;
    PurchFormLetter_Invoice         invoice;

    PurchFormLetter                 confirm;
    VendInvoiceJour                 vendInvoiceJour;
    InvoiceId                       invoiceId;
    PurchLine                       purchLine;
    SalesTable                      salesTable;

    CustInvoiceJour                 custInvoiceJour;
    CustInvoiceId                   custInvoiceId;
    CustPackingSlipJour             custPackingSlipJour;
    PackingSlipId                   packingSlipId;
    VendPurchOrderJour              vendPurchOrderJour;
    DmsInterCompanySO               interCompanySO = new DmsInterCompanySO();
    DmsSOAutoPost                   dmsSOAutoPost = new DmsSOAutoPost();
    DmsCreateSalesOrder             CreateSalesOrder = new DmsCreateSalesOrder();

    purchTable  = _purchTable;//_args.record();
    seq         = this.invoiceCount(purchTable.PurchId);
    seq++;


    try
    {
        select recid from purchLine where purchLine.PurchId == purchTable.PurchId
            && purchLine.PurchReceivedNow != 0;

        if(!purchLine.RecId)
        {
            throw error("@DMS2537");
        }

        ttsBegin;
        if (VendTable::find(purchTable.OrderAccount).DmsSalesKittingEnabled && (purchTable.PurchaseType == PurchaseType::Purch || purchTable.PurchaseType == PurchaseType::ReturnItem))
        {
            DmsPopulateSupplementaryItems::createSupplementaryItemLinesPurch(purchTable);
        }
        if(PurchTable.DmsIsDropShipment)
        {
            CreateSalesOrder.run(PurchTable);
        }

        confirm = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
        confirm.update( purchTable,
                        strFmt('Conf-%1-%2',purchTable.PurchId,seq));

        if(purchTable.InterCompanySalesId && purchTable.PurchaseType == PurchaseType::Purch)
        {
            changeCompany(purchTable.InterCompanyCompanyId)
            {
                select firstonly InvoiceId from custInvoiceJour
                    where custInvoiceJour.SalesId == purchTable.InterCompanySalesId;

                custInvoiceId = custInvoiceJour.InvoiceId;

                select firstonly PackingSlipId from CustPackingSlipJour
                    where CustPackingSlipJour.SalesId == purchTable.InterCompanySalesId;

                packingSlipId = CustPackingSlipJour.PackingSlipId;
            }

            packingSlip = PurchFormLetter::construct(DocumentStatus::PackingSlip);
            packingSlip.showQueryForm(false);
            packingSlip.update( purchTable,
                                packingSlipId,
                                today(),
                                PurchUpdate::ReceiveNow,
                                AccountOrder::None,
                                false,
                                false);

            invoice = PurchFormLetter::construct(DocumentStatus::Invoice);
            invoice.showQueryForm(false);
            invoice.parmDmsReArrangeNow(false);

            invoice.update( purchTable,
                        custInvoiceId,
                        today(),
                        PurchUpdate::PackingSlip,
                        AccountOrder::None,
                        false,
                        false);
        }
        else
        {

            if( purchTable.PurchaseType == PurchaseType::ReturnItem )
            {
                // partner blocking
                //purchTable.DmsPartnerBlockingPurchaseReturnVolume();
                //purchTable.DmsPartnerBlockingPurchaseReturnValue();
                // partner blocking
                confirm = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
                confirm.update(purchTable,'',today(),PurchUpdate::All,AccountOrder::None,NoYes::No,NoYes::Yes);

                if( PurchTable.PurchaseType == PurchaseType::ReturnItem )  //07112015
                {
                    select count(RecId) from vendPurchOrderJour where vendPurchOrderJour.PurchId == PurchTable.PurchId;
                    if(vendPurchOrderJour.RecId > 0)
                    {
                        if( !PurchTable.InterCompanySalesId )
                        {
                            interCompanySO.run(PurchTable.PurchId);
                        }
                    }
                }
            }

            packingSlip= PurchFormLetter::construct(DocumentStatus::PackingSlip);
            packingSlip.showQueryForm(false);
            packingSlip.update( purchTable,
                                strFmt('PS-%1-%2',purchTable.PurchId,seq),
                                today(),
                                PurchUpdate::ReceiveNow,
                                AccountOrder::None,
                                false,
                                false);

            invoice = PurchFormLetter::construct(DocumentStatus::Invoice);
            invoice.showQueryForm(false);
            invoice.parmDmsReArrangeNow(false);

            invoice.update(purchTable,
                        strFmt('INV-%1-%2',purchTable.PurchId,seq),
                        today(),
                        PurchUpdate::PackingSlip,
                        AccountOrder::None,
                        false,
                        false);

        }


        select firstOnly purchTableCurr
            where purchTableCurr.PurchId == PurchTable.PurchId;

        if( purchTableCurr.DmsIsDropShipment && purchTableCurr.DmsDropShipmentSalesId )
        {
            salesTable = SalesTable::find(purchTableCurr.DmsDropShipmentSalesId);
            this.postSO(salesTable);
        }

        ttsCommit;

        invoiceId = strFmt('INV-%1-%2',purchTable.PurchId,seq);

        select LedgerVoucher from vendInvoiceJour where vendInvoiceJour.PurchId && vendInvoiceJour.InvoiceId == invoiceId;

        if(vendInvoiceJour.LedgerVoucher && purchTable.DmsDOReferenceNumber && !purchTable.DmsIsInterCompanyTransfer)
            info(strFmt("@DMS2536",purchTable.PurchId, purchTable.DmsDOReferenceNumber));

    }
    catch
    {
        ttsAbort;
        error("@DMS1832");
    }
}

Friday, 18 December 2015

Thursday, 17 December 2015

use cross company instead of change company more often


    changeCompany(_IMEIDelinkingTable.DataArea)
    {
        select  *
            from   DMSSerialNumTrans
                where DMSSerialNumTrans.SerialNum == _serialNum //serialNumScan.SerialNum
                &&    DMSSerialNumTrans.Company ==  curext()
                &&    DMSSerialNumTrans.IMEITransactionType == DmsSerialTransactionType::Purchase;
        select *
            from VendInvoiceTrans
                where VendInvoiceTrans.InventTransId ==  DMSSerialNumTrans.InventTransId;

        dms_IMEIDelinkingLine.PurchId = VendInvoiceTrans.OrigPurchId;
    }
    */

    select crossCompany InventTransId
            from   DMSSerialNumTrans
                where DMSSerialNumTrans.SerialNum == _serialNum//serialNumScan.SerialNum
                &&    DMSSerialNumTrans.Company ==  _IMEIDelinkingTable.DataArea//curext()
                &&    DMSSerialNumTrans.IMEITransactionType == DmsSerialTransactionType::Purchase
        join  OrigPurchId
            from VendInvoiceTrans
                where VendInvoiceTrans.InventTransId ==  DMSSerialNumTrans.InventTransId
                   && VendInvoiceTrans.dataAreaId == _IMEIDelinkingTable.DataArea;
        /*select OrigPurchId
            from VendInvoiceTrans
                where VendInvoiceTrans.InventTransId ==  DMSSerialNumTrans.InventTransId;*/

        dms_IMEIDelinkingLine.PurchId = VendInvoiceTrans.OrigPurchId;


it is better to use cross company than using change company

Monday, 14 December 2015

how to use table buffer efficently

if(!suppItemGroup)
                        {
                            suppItemGroup.clear();
                            suppItemGroup.GroupId = inventTableModule.SuppItemGroupId;
                            suppItemGroup.Module =  ModuleInventCustVend::Invent;
                            suppItemGroup.insert();                          
                        }                      
                    select ItemId,ModuleType,SuppItemGroupId
                        from inventTableModuleloc
                            where inventTableModuleloc.ItemId         == inventTableModule.ItemId
                                &&    inventTableModuleloc.ModuleType == ModuleInventPurchSales::Sales;                      
                                inventTableModuleloc.clear();
                                inventTableModuleloc.SuppItemGroupId = inventTableModule.SuppItemGroupId;                              
                                inventTableModuleloc.ModuleType      = ModuleInventPurchSales::Sales;
                                inventTableModuleloc.insert();
                                                   
                    select ItemId,ModuleType,SuppItemGroupId
                        from inventTableModuleloc
                            where inventTableModuleloc.ItemId == inventTableModule.ItemId
                                &&    inventTableModuleloc.ModuleType == ModuleInventPurchSales::Purch;                              
                                inventTableModuleloc.clear();
                                inventTableModuleloc.SuppItemGroupId = inventTableModule.SuppItemGroupId;
                                inventTableModuleloc.ModuleType      = ModuleInventPurchSales::Purch;
                                inventTableModuleloc.insert();  


if we see the above code we are using a single table buffer which we are clearing and re inserting it is better than creating a new buffer and using it.


display methods

normally we do caching of display method for the performance issue

best thing we can do is 

we can simple write on every display method top 

as 

[SysClientCacheDataMethodAttribute(true)]

that's it rest of things will be taken care..

no need to add cache method in form data source and normally try to write the display emthods on the tables rather than writing on the form level.

Thursday, 10 December 2015

code to get the child node in product hierchery

static void queryForHierarchyNodes(Args _args)
{
    EcoResCategory          ecoResCategoryMobile, ecoResCategoryInfo, ecoResCategoryLast;
    QueryRun                qRun;
    QueryBuildDataSource    qDS;
    #EcoResCategoryDefaults

    select * from ecoResCategoryMobile where ecoResCategoryMobile.RecId == 5637170077 ;//5637163389;//5637163386; //5637163389;

    qRun        = new QueryRun(new Query());
    qDS = qRun.query().addDataSource(tableNum(ecoResCategory));

    qDS.addRange(fieldNum(EcoResCategory, CategoryHierarchy))
                    .value(queryValue(ecoResCategoryMobile.CategoryHierarchy));

    qDS.addRange(fieldNum(EcoResCategory, NestedSetLeft))
                    .value(Global::queryRange(ecoResCategoryMobile.NestedSetLeft, ecoResCategoryMobile.NestedSetRight));

    qDS.addRange(fieldNum(EcoResCategory, NestedSetRight))
                    .value(Global::queryRange(ecoResCategoryMobile.NestedSetLeft, ecoResCategoryMobile.NestedSetRight));

    while (qRun.next())
    {
        ecoResCategoryInfo  = qRun.get(tableNum(EcoResCategory));
        //select ecoResCategoryLast where ecoResCategoryLast.ParentCategory == ecoResCategoryInfo.RecId;
        //if(!ecoResCategoryLast)
        {
            //info(ecoResCategoryInfo.getLeafNodes().Name);
            info(ecoResCategoryInfo.Name);
        }
    }
}

Wednesday, 9 December 2015

how to form a query based on relation

static void newjob(Args _args)
{
    EcoResDistinctProductVariant        EcoResDistinctProductVariant;
    EcoResProductVariantConfiguration   EcoResProductVariantConfiguration;
    EcoResProductMaster                 resproductmaster;
    EcoResConfiguration                 EcoResConfiguration;
    Query                   query = new Query();
    QueryRun                qr;
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildDataSource    queryBuildDataSource2;
    QueryBuildDataSource    queryBuildDataSource3;
    QueryBuildDataSource    queryBuildDataSource4;
    QueryBuildRange         queryBuildRange;
    QueryBuildRange         queryBuildRange2;
    SysTableLookup          sysTableLookup;
    EcoResConfiguration     EcoResConfiguration1;
 
   
    select * from resproductmaster  where resproductmaster.DisplayProductNumber == "SamsungS20";  
   
    while select * from EcoResDistinctProductVariant  where EcoResDistinctProductVariant.ProductMaster == resproductmaster.RecId
    {      
        select * from EcoResProductVariantConfiguration  where EcoResProductVariantConfiguration.DistinctProductVariant == EcoResDistinctProductVariant.RecId;
        select * from EcoResConfiguration  where EcoResConfiguration.RecId == EcoResProductVariantConfiguration.Configuration;
        info(strFmt("%1",EcoResConfiguration.Name));
    }
   
   
    queryBuildDataSource    = query.addDataSource(tableNum(EcoResConfiguration));
    queryBuildDataSource2   = queryBuildDataSource.addDataSource(tableNum(EcoResProductVariantConfiguration));
    queryBuildDataSource2.addLink(fieldNum(EcoResConfiguration, RecId), fieldNum(EcoResProductVariantConfiguration, Configuration));
    queryBuildDataSource3   = queryBuildDataSource2.addDataSource(tableNum(EcoResDistinctProductVariant));
    queryBuildDataSource3.addLink(fieldNum(EcoResProductVariantConfiguration, DistinctProductVariant), fieldNum(EcoResDistinctProductVariant, RecId));
    queryBuildDataSource4   = queryBuildDataSource3.addDataSource(tableNum(EcoResProductMaster));
    queryBuildDataSource4.addLink(fieldNum(EcoResDistinctProductVariant, ProductMaster), fieldNum(EcoResProductMaster, RecId));
    queryBuildDataSource4.addRange(fieldNum(EcoResProductMaster, DisplayProductNumber)).value("Galaxy S Duos Gold");

    qr = new QueryRun(query);
    while(qr.next())
    {
        EcoResConfiguration1 = qr.getNo(1);
        info(EcoResConfiguration1.Name);
    }
   
}

a query with multiple datasource

public void lookup(FormControl _formControl, str _filterStr)
{
    Query                       query = new Query();
    QueryBuildDataSource        qbds;
    QueryBuildDataSource        qbdsJoin;
    SysTableLookup              sysTableLookup;
    CompanyInfo                 CompanyInfo;
   // super(_formControl, _filterStr);
    changeCompany(DMS_IMEIDelinkingTable.DataArea)
    {
        select firstOnly DMSDivisionCode
            from CompanyInfo
                where CompanyInfo.DataArea == DMS_IMEIDelinkingTable.DataArea;
        sysTableLookup = SysTableLookup::newParameters(tableNum(InventTable), _formControl);

        qbds = query.addDataSource(tableNum(InventTable));
        qbdsJoin = qbds.addDataSource(tableNum(DmsSkuDetailsTable));
        qbds.relations(false);
        qbds.fields().dynamic(NoYes::Yes);
        qbdsJoin.addLink( fieldNum(InventTable, ItemId),fieldNum(DmsSkuDetailsTable, ProductCode));
        qbdsJoin.joinMode(JoinMode::InnerJoin);
        qbdsJoin.addRange(fieldNum(DmsSkuDetailsTable,DivisionCode)).value(CompanyInfo.DMSDivisionCode);
        qbdsJoin.addOrderByField(fieldnum(DmsSkuDetailsTable, ProductCode));
        sysTableLookup.addLookupField(fieldnum(InventTable, ItemId));
        sysTableLookup.addLookupField(fieldnum(InventTable, NameAlias));
        qbds.orderMode(OrderMode::GroupBy);
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }
}

Monday, 7 December 2015

BP error : dateflag should be specified when calling date2str

code  :

  return date2str(_cv.date(),123,2,1,2,1,4);

it wil give bp error :

"date flags should be specified when calling date2str"

Change it too below :

return date2str(_cv.date(),123,2,1,2,1,4,DateFlags::None);





Thursday, 3 December 2015

enable or disable field based on condition ax 2012

there are 2 ways to enable or disable the fields :

1.

inventTable_ds.object(fieldnum(InventTable,ItemId)).enable(True);

2. itemid.enable(true)

always prefer first one as this is considered as best practises
and you don't need set the auto declaration == yes also.


Wednesday, 2 December 2015

Exception -The ' ' character, hexadecimal value 0x20, cannot be included in a name

private void XMLChilddata(DmsTableFieldMapping _mapping,common _recordChild)
{
    str                     strValue;
    XmlAttribute            labelAttribute;
    //InventJournalTable      InventJournalTableloc;
    InventJournalTrans      InventJournalTrans;
    //SysDictField            dict;

    if(_recordChild.TableId == InventJournalTable.TableId)
    {
        while select ItemID
            from InventJournalTrans
                where InventJournalTrans.JournalId == InventJournalTable.JournalId
        {

            childNode = doc.createElement(fieldId2name(tableName2Id("InventJournalTrans"),6));//InventJournalTrans,ItemId));
            labelAttribute = doc.createAttribute("Item  ID");//error here because there is blankspace 
            labelAttribute.value(InventJournalTrans.ItemId);
            childNode.attributes().setNamedItem(labelAttribute);
            strValue  = strFmt("%1",(_recordChild.(fieldnum(InventJournalTrans,ItemID))));
            childNode.innerText(strValue);
            parentNode.appendChild(childNode);
        }
    }

so it should be

private void XMLChilddata(DmsTableFieldMapping _mapping,common _recordChild)
{
    str                     strValue;
    XmlAttribute            labelAttribute;
    //InventJournalTable      InventJournalTableloc;
    InventJournalTrans      InventJournalTrans;
    //SysDictField            dict;

    if(_recordChild.TableId == InventJournalTable.TableId)
    {
        while select ItemID
            from InventJournalTrans
                where InventJournalTrans.JournalId == InventJournalTable.JournalId
        {

            childNode = doc.createElement(fieldId2name(tableName2Id("InventJournalTrans"),6));//InventJournalTrans,ItemId));
            labelAttribute = doc.createAttribute("Item ID");//so no error now
            labelAttribute.value(InventJournalTrans.ItemId);
            childNode.attributes().setNamedItem(labelAttribute);
            strValue  = strFmt("%1",(_recordChild.(fieldnum(InventJournalTrans,ItemID))));
            childNode.innerText(strValue);
            parentNode.appendChild(childNode);
        }
    }

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...