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,
    datemonth::Digits2,dateseparator::None,dateyear::Digits4);

    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);
     while(resultSet.next())
     {
        //---- fields shoud be in numeric order ------
        InventRep.ItemId = resultSet.getString(1);
        InventRep.Qty    = resultSet.getReal(2);
        InventRep.insert();
     }
     CodeAccessPermission::revertAssert();
}

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:


this.printJobSettings().suppressScalingMessage(true);


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

if(this.printJobSettings())
this.printJobSettings().suppressScalingMessage(true);

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;
    ;
    try
    {
        new InteropPermission(InteropKind::ClrInterop).assert();
        cl = new TCSorgula.KPSPublicSoapClient("KPSPublicSoap");
        ret = cl.TCKimlikNoDogrula(_TCID,_name,_surname,_dogumYili);
        CodeAccessPermission::revertAssert();
    }
    catch(Exception::CLRError)
    {
        exceptionTextFallThrough();
    }
    if (_interActive)
    {
        if (ret)
            info("TC ID verified!..");
        else
            warning("Failed TC ID verification!..");
    }
    return ret;
}



My job for run code:

static void TCKimlikTest(Args _args)
{
    ;
    TCKimlik::Sorgula(11111111111,"METİN","EMRE",1911,true);
}


 
 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.

22 Temmuz 2015 Çarşamba

20 Temmuz 2015 Pazartesi

AXAPTA - Remove or add invent reservation

You can add or remove reservation with this code which I learned from Volkan Şişman:

  
InventUpd_Reservation       invUpdReservation; 
... 
//remove 
invUpdReservation = InventUpd_Reservation::newInventDim(InventMovement::construct(invTrans,InventMovSubType::None),myInventDim,200,false);
            invUpdReservation.updateNow();

...
//add
          invUpdReservation = InventUpd_Reservation::newInventDim(InventMovement::construct(invTrans,InventMovSubType::None),myInventDim,400,false);
            invUpdReservation.updateNow();


Or:

//add
     InventUpd_Reservation::updateReserveBuffer(journalTrans, journalTrans.Qty);

//remove
     InventUpd_Reservation::updateReserveBuffer(journalTrans, abs(journalTrans.Qty)); 

Or:

//add

InventUpd_Reservation::newInventDim(InventTrans.inventMovement(true),InventTrans.inventDim(),-InventTrans.qty,true).updateNow();

AXAPTA - Post invent journal which it's form open

If you want to post a record like this, AX will not let you post, with an error about record is using by another. This code part I learned from Volkan Şişman lets to post:

InventJournalCheckPost      journalCheckPost;
JournalForm                 journalForm;

;
...
journalForm      = JournalForm::fromArgs(args);
journalCheckPost = InventJournalCheckPost::newFromForm(args,journalForm);
journalForm.runbaseMainStart();
journalCheckPost.run();
journalForm.runbaseMainEnd(journalCheckPost,false);

15 Temmuz 2015 Çarşamba

AXAPTA - Flexible joins with InventDim Table using InventDimExistsJoin macro

There is a macro to create flexible joins with InventDim table with easy:

InventDimParm       dimParm;
InventDim           dimValues,dimJoin;
;
...
//Fill fields to use join where condition
 dimvalues.wMSLocationId = inventdim.wMSLocationId;
    if (inventdim.InventSiteId)
        dimvalues.InventSiteId = inventdim.InventSiteId;
    if (inventdim.configId)
        dimvalues.configId = inventdim.configId;
 //Set
InventDimParm with fields
    dimparm.initFromInventDim(dimValues);

    while select lclInventSum
        where lclInventSum.ItemId == itemId && leftQty > 0
              #InventDimExistsJoin(lclInventSum.InventDimId,dimJoin,dimValues,dimParm)


First parameter was related InventDimId field for join tables, second is InventDim tables local alias, values go with third parameter. The last one is parameter table. There ara different usages of that table.