22 Temmuz 2013 Pazartesi

AXAPTA - Setfocus to a specified control when opening form

Should write a setfocus for control at form's firstField method:

public void firstField(int _flags=1)
{
    super(_flags);
    EmplId2.setFocus();
}

12 Temmuz 2013 Cuma

AXAPTA - Timezone difference when getting server datetime value

DateTimeUtil classes utcNow method gives time as  Greenwich time. When getting and setting datetime it needs convert:

CallDateTime.value(DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::utcNow(),DateTimeUtil::getCompanyTimeZone()));
...

...
JournalLines.CallDateTime = DateTimeUtil::removeTimeZoneOffset(CallDateTime.value(),DateTimeUtil::getCompanyTimeZone());

11 Temmuz 2013 Perşembe

AXAPTA - Print barcode

Blogs about barcode printing with Axapta usually same each other. There are some problems with Axapta barcode printing and none of them mentioned these problems. I wrote tricks about them at this page:

Code 128:

display BarCodeString ServiceObjectbarCode()
{
    Barcode barcode;
    ;

    barcode = BarcodeCode128::construct();
    barcode = Barcode::construct(BarcodeType::Code128);


    barcode.string(true, ServiceObject.ItemSerialNum);
    barcode.encode();
    return barcode.barcodeStr();
}


After drag and drop this display method to report section:

Font - BC C128 Narrow

Width - This value shouldn't be auto. Axapta terminate label before needed length. Needed length can find with a few try. I used 10 cm with my sample.
Fontsize - 24 (I couldn't success write readable barcodes below 24. Some bigger font sizes cannot read with barcode reader too, need tries).

Code 39 :
display BarCodeString ServiceOrderbarCode()
{
    Barcode barcode;
    ;

    barcode = Barcode::construct(BarcodeType::Code39);
    barcode.string(true, ServiceOrder.ServiceOrderId);
    barcode.encode();

    return barcode.barcodeStr();
}


Font - BC C39 3 to 1 HD Wide
I didn't have trouble when using Code39 about width property when selected Auto. Like Code 128 I had trouble with font sizes below 24 and some sizes upper 24. It may be about my barcode reader.

4 Temmuz 2013 Perşembe

AXAPTA - Set cursor to a record fast with grid

Findrecord and findvalue methods are so slow for set a record for current. Instead of these filter method can be use but with filter just filtered records can be view. If you want see all records and set cursor to a specific record can use this way which I found  at a blog uses from Axapta with also original lookup forms:

element.args().lookupField(fieldnum(SMAServiceOrderTable, ServiceOrderId));
element.args().lookupValue(_order.ServiceOrderId);
 

SMAServiceOrderTable_ds.executeQuery();


It's so fast but don't forget to use indexed field for search.

24 Haziran 2013 Pazartesi

AXAPTA - Make display methods faster with cacheAddMethod

Axapta may call display methods over and over when navigating in table. If there are a lot of display methods it would be a trouble. cacheAddMethod provides save display methods at server and gives good performance increase. This method can be call after datasource's init method. If called from at wrong place it would be a reason of frozen of Axapta. Also this type display methods should be "table" methods.
This technique also works for edit methods.
public void init()
{
    super();
    this.cacheAddMethod(tableMethodStr(B_CallTrack, CustomerName));
    this.cacheAddMethod(tableMethodStr(B_CallTrack, EndUserWarrantyStart));
    this.cacheAddMethod(tableMethodStr(B_CallTrack, ExtendedWarrantyDate));
    this.cacheAddMethod(tableMethodStr(B_CallTrack, ModelGroupID));
}


Cached display/edit methods don't update before update methods run. When necessary refresh display methods before update, you may use cacheCalculateMethod:
B_CallTrack_DS.cacheCalculateMethod(tableMethodStr(B_CallTrack, EndUserWarrantyStart));
 


Update for AX 2012:

This process eaiser with AX 2012. You can  use SysClientCacheDataMethodAttribute. There's an optiona parameter too. If you send true for this parameter update issue at upper solved with automatically. But with this way display/edit method will be cached in all forms. If you don't want this old way sill valid.


[SysClientCacheDataMethodAttribute(true)]
display name dispCustName()
{
    return CustTable::find(this.CustAccount).Name;
}

AXAPTA - Display method authorization check

//BP Deviation documented
display CustName customerName()
{
    CustName    custName    = '';
    DictTable   dictTable   = new DictTable(tablenum(CustTable));
    ;

    if (dictTable.rights() >= AccessType::View)
    {
        custName = CustTable::find(this.CustAccount).Name;
    }

    return custName;
}

6 Haziran 2013 Perşembe

AXAPTA - Begin and end of the day

     info( strfmt("%1 --- %2", datetobeginUtcDateTime( today() , DateTimeUtil::getUserPreferredTimeZone() ) ,
        datetoendUtcDateTime( today(), DateTimeUtil::getUserPreferredTimeZone() )));