Tuesday, February 24, 2015

Read odata service in ax 2012 + vs.net c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Services.Client;




namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {

                Uri url = new Uri("http://win-nc3sculi90s:8101/DynamicsAx/Services/ODataQueryService/");
                var container = new productservice.ODataQueryService(url);
                //productservice.ODataQueryService context = new productservice.ODataQueryService(url);
                container.Credentials = System.Net.CredentialCache.DefaultCredentials;

                var ibnTable = from p in container.IBN_table
                               select p;

                foreach (var data in ibnTable)
                {
                    Console.WriteLine(data.IBN_table_1_Name);
                   
                }
                Console.ReadLine();
             

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                Console.ReadLine();
            }

        }
    }
}

Monday, February 9, 2015

Query in AX 2012

How to create Query in AX 2012 through X ++ code

With the following job we can create and execute the query :

Static void Querytest(Args _Args)
{
    Query query;
    QueryBuildDataSource queryBuildDataSource;
    QueryBuildDataSource queryBuildDataSource1;
    QueryBuildRange queryBuildRange;
    QueryRun  queryRun;
    CustTable custTable;
    DirPartyTable DirPartyTable;
    ;
    query=new query();      //Initialize Query
    queryBuildDataSource=query.addDataSource(tableNum(CustTable));   //Add Query
    queryBuildDataSource.addSortField(fieldNum(custTable,AccountNum),SortOrder::Descending); //Add sorting
    queryBuildRange=queryBuildDataSource.addRange(fieldNum(CustTable,AccountNum)); // Add Range
    queryBuildRange.value(queryValue('11')+('*')); // Add Query Value
    queryBuildRange=queryBuildDataSource.addRange(FieldNum(CustTable,AccountNum));
    queryBuildRange.value(queryValue('22')+('*'));
   
    //queryBuildDataSource1=queryBuildDataSource.addDataSource(tableNum(CustTrans)); //Add other Data Source for Joining
    //queryBuildDataSource1.relations(true);// Enable Relation
    // queryBuildDataSource1.joinMode(JoinMode::InnerJoin);//Define Join Mode
   
    queryRun= new QueryRun(query);   //Pass query to run it
    while(queryRun.next())
    {
        custTable=queryRun.get(tableNum(CustTable));
        print(strFmt("Customer Name, Account num and Currency are  %1 , %2 and %3",DirPartyTable::findRec(CustTable.Party).Name,CustTable.AccountNum,CustTable.Currency));
        pause;
    }

}

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...