Showing posts with label HOW. Show all posts
Showing posts with label HOW. Show all posts

Wednesday, November 22, 2017

HOW TO GET DAY OF THE WEEK IN MICROSOFT DYNAMICS AX

HOW TO GET DAY OF THE WEEK IN MICROSOFT DYNAMICS AX 
static void dayOfWkExample(Args _arg)
{
    date d = today();
    int i;
    ;
    i = dayOfWk(d);
    print "Today's day of the week is " + int2Str(i);
    pause;
}

Thursday, June 8, 2017

How to Upload License in Microsoft Dynamics AX 2012 :MICROSOFT DYNAMICS AX 2012

How to Upload License in Microsoft Dynamics AX 2012 :MICROSOFT DYNAMICS AX 2012

Go To System administration > Setup > Licensing > License information.
Then Click Load license file to import the license codes from a file and select license file.
Click  OK button.

This will also Synchronize the database.


HOW TO REMOVE BLANK SPACES IN AX: AX 2012 MICROSOFT DYNAMICS AX 2012 :AX 2009

HOW TO REMOVE BLANK SPACES IN AX: AX 2012 

MICROSOFT DYNAMICS AX 2012 :AX 2009


Just replace the code with the below syntax.

strRTrim(strLTrim(Dirpartytable.Name));  

Thursday, May 4, 2017

MICROSOFT DYNAMICS AX 2012 : HOW TO USE QUERYHAVINGFILTER IN AX 2012: QUERY WITH GROUP CONDITION

How to use QueryHavingFilter in AX 2012

 QueryHavingFilter:

Consider the following scenario. The CUSTTABLE table has a field called CUSTGROUP, indicating the customer group the customer belongs to. We would like to get a list of all customer groups that have less than 4 customers in them.
Traditionally, in AX queries, we can group by the CUSTGROUP field, COUNT the RecIds. However, there was no way to filter on that counted RecId field. However, in SQL, the having statement gives you that ability:

SELECT CUSTGROUP, COUNT(*) FROM CUSTTABLE
        GROUP BY CUSTGROUP
        HAVING COUNT(*) < 4

In AX you can count, group by, but you'll need to loop over the results and check the counter manually if you want to filter values out. So, in AX 2012, a new query class was added: QueryHavingFilter, that lets you do just that:

static void QueryHaving(Args _args)
{
    Query                   query;
    QueryBuildDataSource    datasource;
    QueryBuildRange         range;
    QueryHavingFilter       havingFilter;
    QueryRun                queryRun;
    int                     counter = 0, totalCounter = 0;
    CustTable               custTable;
   
    query = new Query();
    datasource = query.addDataSource(tableNum(CustTable));
    datasource.addSelectionField(fieldNum(CustTable, RecId),
            SelectionField::Count);
    datasource.orderMode(OrderMode::GroupBy);
    datasource.addGroupByField(fieldNum(CustTable, CustGroup));
   
    havingFilter = query.addHavingFilter(datasource, fieldStr(custTable, RecId),
            AggregateFunction::Count);
    havingFilter.value('<4 o:p="">
   
    queryRun = new QueryRun(query);
    while (queryRun.next())
    {
        custTable = queryRun.getNo(1);
        info(strFmt("Group %1: %2", custTable.CustGroup, custTable.RecId));
    }
}


Note that in this code example, I added a selection field on RecId and used SelectionField::Count. This is not necessary for the having filter to work, the only reason it is in the code example is to be able to show it in the infolog (ie to have the count value available). So it is independent of the HavingFilter!


Monday, April 18, 2016

HOW TO CREATE A DIALOG IN DYNAMICS AX : X++ CODE

CREATE A DIALOG IN AX : X++ CODE 


class CustDialog extends RunBase
{
DialogField fieldAccount;
DialogField fieldName;
DialogField fieldGroup;
DialogField fieldCurrency;
}

pack() and unpack(0 are used to retain the last used values.
public container pack()
{
return conNull();
}
public boolean unpack(container _packedClass)
{
return true;
}
protected Object dialog()
{

Dialog dialog;
DialogGroup groupCustomer;
DialogGroup groupPayment;
dialog = super();
dialog.caption("Customer information"); dialog.allowUpdateOnSelectCtrl(true);
fieldAccount = dialog.addField(
extendedTypeStr(CustAccount), "Customer account");
fieldName = dialog.addField(extendedTypeStr(CustName));
fieldName.enabled(false);
dialog.addTabPage("Details");
groupCustomer = dialog.addGroup("Setup");
fieldGroup = dialog.addField(
extendedTypeStr(CustGroupId)); fieldCurrency = dialog.addField(
extendedTypeStr(CurrencyCode)); fieldGroup.enabled(false);
fieldCurrency.enabled(false);
groupPayment = dialog.addGroup("Payment");
return dialog;
}

Below method is used to dynamically assign the different values of the cust table
public void dialogSelectCtrl()
{
CustTable custTable;
custTable = CustTable::find(fieldAccount.value()); fieldName.value(custTable.name()); fieldGroup.value(custTable.CustGroup); fieldCurrency.value(custTable.Currency);
}
public static void main(Args _args)
CustSelect custSelect = new CustSelect();
if (CustSelect.prompt()) {
CustSelect.run();
}
}

READ COMMA SEPARATED FILES : DYNAMIC AX CODE X++

READ COMMA SEPARATED FILES : DYNAMIC AX CODE X++
PUBLIC VOID READCOMMAFILE()
{
CommaTextIo         file;
container           line;
#define.filename(@'C:\\accounts.csv') #File
file = new CommaTextIo(#filename, #io_read);
if (!file || file.status() != IO_Status::Ok)
{
throw error("File cannot be opened.");
}
line = file.read();
while (file.status() == IO_Status::Ok)
{
info(con2Str(line, ' - '));
line = file.read();
                }


}

CREATE COMMA SEPARATED FILES : DYNAMICS AX X++ CODE

CREATE COMMA SEPARATED FILES : DYNAMICS AX X++ CODE
public void createcommafiles()
{
CommaTextIo         file;
container            line;
MainAccount           mainAccount;
#define.filename(@'C:\accounts.csv') #File
file = new CommaTextIo(#filename, #io_write);
if (!file || file.status() != IO_Status::Ok)
{
throw error("File cannot be opened.");
}
while select MainAccountId, Name from mainAccount
{
line = [
mainAccount.MainAccountId,
mainAccount.Name];
file.writeExp(line);
}
info(strFmt("File %1 created.", #filename));

}

CODE TO ADD A NOTE IN A DOCUMENT REFERENCE FOR A TABLE

CODE TO ADD A NOTE IN A DOCUMENT REFERENCE 
FOR A TABLE

static void TabledocuAdd(Args _args) {
DocuRef      docuRef;
VendTable vendTable;
vendTable = VendTable::find('123');
docuRef.RefCompanyId = vendTable.dataAreaId;
docuRef.RefTableId    = vendTable.TableId;
docuRef.RefRecId        = vendTable.RecId;
docuRef.TypeId        = 'Note';
docuRef.Name            = 'Imported';
docuRef.Notes         = 'This vendor was imported.';
docuRef.insert();

}

Outbound and Inbound file generation using File system adapater in AX 2012

Outbound  and Inbound file generation using File system adapter in AX 2012


Below is the code to generate the outbound xml file for the selected record.
static void GenerateXmlSelectedRecord(Args _args)
{
    AxdSendContext      axdSendContext  = AxdSendContext::construct();
    AifEntityKey        aifEntityKey    = AifEntityKey::construct();
    AifEntityKeyList    aifEntityKeyList = AifEntityKeyList::construct();
    Map                 keyData;
    AifConstraintList   aifConstraintList   = new AifConstraintList();
    AifConstraint       aifConstraint       = new AifConstraint();
    CustTable           custTable;
    int i,j;
    CustCustomerService CustCustomerService = CustCustomerService::construct();
    ;
    custTable = CustTable::find('Cust001');

    keyData = SysDictTable::getKeyData(custTable);
    aifEntityKey.parmTableId(custTable.TableId);
    aifEntityKey.parmRecId(custTable.RecId);
    aifEntityKey.parmKeyDataMap(keyData);

    aifEntityKeyList.addEntityKey(aifEntityKey);


    axdSendContext.parmXMLDocPurpose(XMLDocPurpose::Original);
    axdSendContext.parmSecurity(false);


    aifConstraint.parmType(AifConstraintType::NoConstraint) ;
    aifConstraintList.addConstraint(aifConstraint) ;

    info(strFmt("%1",custTable.AccountNum));
    AifSendService::SubmitDefault(  classnum(CustCustomerService),
                                aifEntityKey,
                                aifConstraintList,
                                AifSendMode::Async,
                                axdSendContext.pack());
}

Example: Generating the outbound xml file for all records( i.e. specified criteria on the query).
Below is the code to generate the outbound xml for all the records or specified criteria.

static void GenerateMutiplerecords(Args _args)
{
    CustTable           custTable;
    AxdSendContext      axdSendContext      = AxdSendContext::construct();
    AifEntityKey        aifEntityKey        = AifEntityKey::construct();
    AifConstraintList   aifConstraintList   = new AifConstraintList();
    AifConstraint       aifConstraint       = new AifConstraint();
    AifEndpointList     endpointList;
    AifActionId         actionId;
    Query               query;
    QueryBuildDataSource    qbds;

    query               = new Query(queryStr(AxdCustomer));
    AxdSend::removeChildDs(query);

    actionId            = AifSendService::getDefaultSendAction(classnum(CustCustomerService), AifSendActionType::SendByQuery);
    aifConstraint.parmType(AifConstraintType::NoConstraint);
    aifConstraintList.addConstraint(aifConstraint) ;
    endpointList        = AifSendService::getEligibleEndpoints(actionId, aifConstraintList);

    AifSendService::SubmitFromQuery(actionId,endpointList,query,AifSendMode::Async);
}

Saturday, April 16, 2016

Change Color of your Dynamics AX Environments/Forms

 Change Color of your Dynamics AX  Environments/Forms


To change the color of the Dynamics forms to help indicate what environment is in use. It involved overriding the SysSetupFormRun.run() method, which will be called every time a form is opened. On the class SysSetupFormRun, create a new method with this code:
public void run()
{
SysSQLSystemInfo systemInfo = SysSQLSystemInfo::construct();
; 

super();
// Set the color scheme of this instance of the SysFormRun to RGB
this.design().colorScheme(FormColorScheme::RGB);
// If the database name is not the live version, change the color of the form
if (systemInfo.getloginDatabase() != 'DynamicsAX_test')
this.design().backgroundColor(0x112255);
}



 If your live and test systems use the same database name, but the AOS is running on different servers you can modify this code to to match on systemInfo.getLoginServer() != 'MyServerName'. You can change the color by setting the hex value. It uses the RGB values in reverse order: 0xBBGGRR. 

thanks,
Vikas Mehta

HOW TO PRINT A DIFFERENT SALES INVOICE PER COMPANY IN AX :VIKAS MEHTA

How to print a different Sales Invoice per company in AX

If you want to print a different Sales Invoice per every company you have,  change the method printJournal in the table CustInvoiceJour and the form CustInvoiceJournal (MenuButton "SalesInvoiceShow" -> Copy, Original and Original print):

Modified method printJournal for the table CustInvoiceJour:
server void  printJournal(SalesFormLetter      salesFormLetter = null,
                          RecordSortedList     journalList     = null,
                          NoYes                copy            = NoYes::No)
{
    Args                parameters = new Args();
    MenuFunction        salesInvoiceMenu;
    ;

    // Show the correct report for the every company in AX
    switch (strupr(curExt()))
    {
        case "CEU":
            salesInvoiceMenu = newMenuFunction(menuitemoutputstr(OPPSalesInvoice),MenuItemType::Output);
            break;
       
        default:
            salesInvoiceMenu = newMenuFunction(menuitemoutputstr(SalesInvoice),MenuItemType::Output);
    }
    // End

    parameters.caller(salesFormLetter);

    if (journalList)
        parameters.object(journalList);
    else
        parameters.record(this);

    salesInvoiceMenu.run(parameters);
}


For every MenuItemButton below the SalesInvoiceShow, you must override the clicked method as follows:
void clicked()
{
    Args                parameters = new Args();
    MenuFunction        salesInvoiceMenu;
    ;

    // Let the menuItemButton as this, with original parameters but
    // don't call super, to avoid call directly to report SalesInvoice
    //super();

    switch (strupr(curExt()))
    {
        case "OPP":
            salesInvoiceMenu = newMenuFunction(menuitemoutputstr(OPPSalesInvoiceCopy),MenuItemType::Output);
            break;

        default:
            salesInvoiceMenu = newMenuFunction(menuitemoutputstr(SalesInvoiceCopy),MenuItemType::Output);


Thanks,
Vikas Mehta.

SALES QUOTE UPDATION AX 2012 X++ CUSTOM WEB SERVICE

SALES QUOTE UPDATION AX 2012 
X++ CUSTOM WEB SERVICE
Sales Quote update
[AifCollectionTypeAttribute('return', Types::Container), SysEntryPointAttribute(true)]
public str updateQuote(QuotationIdBase _quoteId,CustCurrencyCode _currency, InventSiteName _site,ItemIdSmall _item,SalesQty _qty,comp_OrderType _orderType,comp_OrderCat _orderCategory,FormType_IN _saleTypeSalesTax,comp_SaleTypeExciseDuty   _saleTypeExcise,
                        String50 _domestic,String50 _export,String50 _e1Sale,string50 _price,TaxGroup _taxGroup,MarkupValue _freight)
{

    str                             log;
    str                             log_1,log_2,log_3,log_4,log_5,log_6,log_7,log_8,log_9;
    Inventsite                      site;
    InventLocation                  ware;
    SalesQuotationTable             quotation,quotationIdchk;
    SalesQuotationLine              line,line_2;
    InventDim                       dim;
    InventItemOrderSetupType        setupType   = InventItemOrderSetupType::Invent;
    InventTable                     inventTable;
    CustTable                       cust;
    InventDimCombination            comb;
    NoYes                           noyes;
    TmpTaxWorkTrans                 tmpTax;
    SalesQuotationTable             salesQuotationTable;
    SalesQuotationTotals_Sales      salesQuotationTotals;
    TaxTable                        taxtable;
    str                             component;
    container                       con;
    int                             i ;
    compProductMasterDefault         prodMasterDef;
    MarkupTable                             markTab;
    MarkupTrans                             trans;

    select * from prodMasterDef;

   if(_orderCategory == 'Dealer-Customer')
            changeCompany(prodMasterDef.DealerCompany)
    {  // Validating from masters
         select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;
     if(quotationIdchk.RecId && InventSite::exist(_site) && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)&&  TaxGroupHeading::exist(_taxGroup))

        {

            ttsBegin;
            //updating header
            quotation.clear();
            select forupdate quotation where quotation.QuotationId ==  _quoteId;
            if(quotation.RecId)
            {
                quotation.QuotationStatus  = SalesQuotationStatus::Created;
                quotation.CurrencyCode = _currency;
                quotation.ShippingDateRequested = systemDateGet();
                quotation.comp_OrderType = _orderType;
                quotation.comp_OrderCat  = _orderCategory;
                quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
                quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
                quotation.comp_Domestic = str2enum(NoYes,_domestic);
                quotation.comp_Export = str2enum(NoYes,_export);
                quotation.update();
            }
            //updating line
            line.clear();
            select forUpdate line where line.QuotationId == quotation.QuotationId;
                               // && line.ItemId == _item;

            if(line.RecId)
            {
                 //line.ItemId = _item;
                line.initFromSalesQuotationLine(line);
                 line.SalesPrice = str2num(_price) - _freight;
                 line.TaxGroup = _taxGroup;
                 line.SalesQty = _qty;
                 line.CurrencyCode = _currency;
                 line.ShippingDateRequested = systemDateGet();
                 line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
                 line.ExciseTariffCodes_IN = Inventtable::find(line.ItemId).ExciseTariffCodes_IN;
            }
            line.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line.update();


            markTab = MarkupTable::find((MarkupModuleType::Cust),'6');

            select forupdate trans where Trans.TransTableId == line.TableId
                    && Trans.TransRecId == line.RecId;
           trans.ModuleType  =  MarkupModuleType::Cust;
           trans.CurrencyCode = line.CurrencyCode;
           trans.MarkupCode    = markTab.MarkupCode;
           trans.Txt            = markTab.Txt;
           trans.MarkupCategory = MarkupCategory::Pcs;
           trans.Value = _Freight;
           Trans.update();
            ttsCommit;
            salesQuotationTable  = SalesQuotationTable::find(_quoteId);
            salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);

            // Calculate Tax
            salesQuotationTotals.calc();

            // Load tmpTaxWorkTrans
            tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());

            // Showing taxes with tax value
            while
                select tmpTax
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
               log_7  = component;
//             log_8 = num2str(abs(tmpTax.TaxAmount),0,2,1,1);
               log_8 =  num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
               con = conins(Con,i,log_7+':'+log_8);


            }
            i =0 ;
            log = con2StrUnlimited(con,'|');

         }
        else
        {
            //strFmt('Warehouse %1 is not valid for Sales Quote : %2',ware,_quoteId);
            if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for %2 company %3',_item,_quoteId,curext());
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strFmt('SalesTax FormType %1 is not valid for %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is %1 not valid for %2',_taxGroup,_quoteId);
            }
            if(!quotationIdchk.RecId )
            {
                log_9 = strFmt('Quote %1 does not exist',_quoteId);
            }
            log = strFmt("%1\n%2\n%3\n%4",log_3,log_4,log_5,log_9);

        }

      }
      else
      {
           changeCompany(prodMasterDef.delCompany)
          {
       // validating masters
           select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;
      if( quotationIdchk.RecId && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)&&  TaxGroupHeading::exist(_taxGroup))

        {
             ttsBegin;
            //creating header
            quotation.clear();
            select forUpdate quotation where quotation.QuotationId == _quoteId;
            if(quotation.RecId)
            {
                quotation.QuotationStatus  = SalesQuotationStatus::Created;
                quotation.CurrencyCode = _currency;
                quotation.ShippingDateRequested = systemDateGet();
                quotation.LanguageId = SystemParameters::getSystemLanguageId();
                quotation.comp_OrderType = _orderType;
                quotation.comp_OrderCat  = _orderCategory;
                quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
                quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
                quotation.comp_Domestic = str2enum(NoYes,_domestic);
                quotation.comp_Export = str2enum(NoYes,_export);
                quotation.update();
            }
            //updating lines
            line.clear();
            select forUpdate line where line.QuotationId == quotation.QuotationId;
                      //  && line.ItemId == _item;

            if(line.RecId)
            {
                 //line.ItemId = _item;
                 line.initFromSalesQuotationLine(line);
                 line.SalesPrice = str2num(_price) - _freight;
                 line.TaxGroup = _taxGroup;
                 line.SalesQty = _qty;
                 line.CurrencyCode = _currency;
                 line.ShippingDateRequested = systemDateGet();
                 line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
                 line.ExciseTariffCodes_IN = Inventtable::find(line.ItemId).ExciseTariffCodes_IN;
            }
            line.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line.update();

             markTab = MarkupTable::find((MarkupModuleType::Cust),'6');

            select forupdate trans where Trans.TransTableId == line.TableId
                    && Trans.TransRecId == line.RecId;
               trans.ModuleType  =  MarkupModuleType::Cust;
               trans.CurrencyCode = line.CurrencyCode;
               trans.MarkupCode    = markTab.MarkupCode;
               trans.Txt            = markTab.Txt;
               trans.MarkupCategory = MarkupCategory::Pcs;
               trans.Value = _Freight;
               Trans.update();
            ttsCommit;
            salesQuotationTable  = SalesQuotationTable::find(_quoteId);
            salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);

            // Calculate Tax
            salesQuotationTotals.calc();

            // Load tmpTaxWorkTrans
            tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());

            // Showing taxes with tax value
             while
                select tmpTax
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
               log_7  = component;
               log_8 = num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
               con = conins(Con,i,log_7+':'+log_8);


            }
            i =0 ;
            log = con2StrUnlimited(con,'|');

         }
        else
        {
              if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for %2 for company %3',_item,_quoteId,curext());
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strFmt('SalesTax FormType %1 is not valid for %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is %1 not valid for %2',_taxGroup,_quoteId);
            }
             if(!quotationIdchk.RecId )
            {
                log_9 = strFmt('Quote %1 does not exist for company %2',_quoteId,curext());
            }
            log = strFmt("%1\n%2\n%3\n%4",log_3,log_4,log_5,log_9);
        }
      }
    }

     info(strFmt("Sales Quote Update: %1 - %2 ",_quoteId,log));
     comp_RetailExceptionActivityLog::logEvent('Sales Quote Update',infolog.export());
     return log ;
    }
Related Posts Plugin for WordPress, Blogger...