27 Ağustos 2015 Perşembe

AXAPTA - Save query to a table field and restore than

I used Mirko Bonello's blog for this sample.

Create a container field at table. Mine is InventTableQuery:

void createAndSaveQueryInTable()
  QueryRun SysqueryRun;
  if (this.InventTableQuery)
      queryRun = new QueryRun(this.InventTableQuery);
      queryRun = new QueryRun(queryStr('InventTable'));

   if (queryRun.prompt())
      this.InventTableQuery = queryRun.pack();

We used SysQueryRun instead for QueryRun and set qrun.promptLoasLastUsedQuery(false) for don't screw like me because of "Why I get same query values for every record?" question... :)

AXAPTA - Write text file

    TextIo           textIo;
    str              fileName;
    FileIOPermission fioPermission;
        fileName = "c:\\myfolder\\test.txt"
        fioPermission = new FileIOPermission
            (fileName ,"RW");
        if (WINAPI::fileExists(fileName))
        textIo = new TextIo(fileName, #IO_WRITE);
            textIo.write("test 12");
            textIo.write("test 34");
        textIo = null;

19 Ağustos 2015 Çarşamba

AXAPTA - Execute direct SQL statement

The sample given at that  blog worked for me good. Unfortunately in sample at this blog and others always read just one field from query. I got an error about index when try to read fields more than one. Later I learned I have to read fields in ascending numeric order from a Microsoft's  page . Run method from server side. In the other case you wold be get a security error. For insert ve delete (however this's not an advicable way for Axapta tables) instead of executeQuery you can use executeUpdate.

public server static InventRep FillSQL(DatePhysical _DatePhysical = today())
    InventRep   InventRep;

    Connection      connection;
    Statement       statement;
    str             query,dateStr;
    Resultset       resultSet;


    dateStr = date2str(_DatePhysical,321,dateday::Digits2,dateseparator::None,

    connection = new Connection();
    statement = connection.createStatement();
    query =
        "select ITEMID,SUM(QTY)"+
        "from INVENTTRANS "+
        "where DATAAREAID='TST'"+
        "and DATEPHYSICAL <='"+dateStr+"' "+
        "group by ITEMID "+
        "having SUM(QTY) <>0";
     new SqlStatementExecutePermission(query).assert();
     resultSet = statement.executeQuery(query);
        //---- fields shoud be in numeric order ------
        InventRep.ItemId = resultSet.getString(1);
        InventRep.Qty    = resultSet.getReal(2);

12 Ağustos 2015 Çarşamba

AX 2009 - Ride off warning message when report doesn't fit to screen

If Axapta reports don't fit in screen warn you. If this message bothers you, put this in report init method:


There had be a way to ride off this message all of your reports. Put these lines into SysReportRun classes Run method before super():


5 Ağustos 2015 Çarşamba

AX 2009 - Consume web service with TC ID number test sample

I rewrite sample which I wrote for 2012. When I write the service I used Microsoft'un white page about consume web services in 2009. White page written for a web service which is not avaliable than but anyway worked.

First run AOT->References->Add service reference:

Write https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx?WSDL to WSDL URL field.

I wrote TCSorgula to .NET code namespace field. I left reference name field with default written TCSorgula value.

After I wrote this method:

public server static boolean Sorgula(Int64 _TCID,str _name,str _surname, int _birthDate, boolean _interActive = false)
    TCSorgula.KPSPublicSoapClient  cl;
    boolean ret;
    System.Exception                      ex;

    str st;
        new InteropPermission(InteropKind::ClrInterop).assert();
        cl = new TCSorgula.KPSPublicSoapClient("KPSPublicSoap");
        ret = cl.TCKimlikNoDogrula(_TCID,_name,_surname,_dogumYili);
    if (_interActive)
        if (ret)
            info("TC ID verified!..");
            warning("Failed TC ID verification!..");
    return ret;

My job for run code:

static void TCKimlikTest(Args _args)

 TC ID verification service returns false when name or birthdate is wrong in case invalid ID strangely run exception. I was catching this case in AX 2012 with search "T.C. Kimlik No alanına girdiğiniz değer geçerli bir T.C. Kimlik Numarası değildir" value in return error string. Unfortunately I failed this with 2009. So I can just catch correct ID or invalid ID/failed service.

If VS doesn't installed you can install .NET framework SDK.