30 Kasım 2011 Çarşamba

AXAPTA empty InventDimId

InventDimId is a mandatory field for some tables. If you don't use it, you can left it blank:

SMAServiceBOMTable.InventDimId  = InventDim::inventDimIdBlank();

AXAPTA Query: empty records, not empty records, use enum at query value

We have to put parameters when we want to do a complex addrange  at query. But it's not necessary with some situations:

Not empty records:
    qbds.addRange(fieldnum(custtable,name)).value(sysquery::valueNotEmptyString()) ;
Empty records:
    qbds.addRange(fieldnum(custtable,name)).value(sysquery::valueEmptyString()) ;
Records are not equal 10000:
    qbds.addRange(fieldnum(custtable,accountnum)).value(sysquery::valueNot("10000") ) ;
Ranges:
    qbds.addRange(fieldnum(custtable,accountnum)).value(queryrange("1","10000") ) ;
Enum:
            qbds.addRange(fieldnum(B_RMARequestTable, RefType)).value(queryvalue(B_RMAReqRefType::RepairJournal));

AXAPTA use number sequence at insert record with code

B_RepairJournalPartsChange.ChangeNo               = NumberSeq::newGetNum(SMAParameters:: numRefRMARequestNo()).num();

AXAPTA create number sequence

First we have to find table and class for our module. Mine is SMAParameters .

My table is SMAParameters (It can find from modules parameters screen, setup tab). Add this method to table:

public server static NumberSequenceReference numRefRMARequestNo()
{
    return NumberSeqReference::findReference(
            typeid2extendedtypeid(typeid(B_RMARequestNo)));
}


Update for AX 2012:

Instead of

typeid2extendedtypeid(typeid(B_RMARequestNo))

write

extendedTypeNum(SNBmasterNum) 


"B_RMARequestNo" at here is our tables key field's extended data type.


After that we have to go number sequence class. Related class name can be find from parameter table's numberSeqModule method. Write this code part at loadModule method:

    /* RMA Request No */
    numRef.DataTypeId              = typeId2ExtendedTypeId(typeid(B_RMARequestNo));
    numRef.ConfigurationKeyId      = configurationkeynum(SMAManagement);
    numRef.ReferenceHelp           = literalstr("My Number Seq...");
    numRef.WizardContinuous        = false;
    numRef.WizardFetchAheadQty     = 20;
    numRef.WizardManual            = NoYes::No;
    numRef.WizardAllowChangeDown   = NoYes::No;
    numRef.WizardAllowChangeUp     = NoYes::No;
    numRef.SortField               = 11;
    this.create(numRef);

Put upper numberseqs sortfield value +1 to Sortfield field.

Update for AX 2012:
Before launch wizard run this command

NumberSeqApplicationModule::loadAll();

Then Basic->Setup->Number sequences->Number sequences. Run Wizard.

Look service parameters->number sequence tab at related modules menu for check.

Now we can use this number sequence at forms...

Add this line at forms classDeclaration method:

NumberSeqFormHandler numberSeqFormHandler;

Add this method to form:

NumberSeqFormHandler numberSeqFormHandler()
{
    ;
    if (!numberSeqFormHandler)
    {

        numberSeqFormHandler = NumberSeqFormHandler::newForm(SMAParameters::numRefRMARequestNo().NumberSequence,
                                                             element,
                                                             B_RMARequestTable_DS,
                                                             fieldnum(B_RMARequestTable,RequestNo));
    }
    return numberSeqFormHandler;
}

Update: Upper line should be like below for AX 2012:

numRefRMARequestNo().NumberSequenceId 
instead of
numRefRMARequestNo().NumberSequence


B_RMARequestTable_DS is my tables datasource. RequestNo is key field.

Form close method:

public void close()
{
    if (numberSeqFormHandler)
    {
        numberSeqFormHandler.formMethodClose();
    }
    super();
}

Data source methods:

public void linkActive()
{
    ;
    element.numberSeqFormHandler().formMethodDataSourceLinkActive();
    super();
}

public boolean validateWrite()
{
    boolean ret;

    ret = super();
    ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;

    return ret;
}

public void write()
{
    super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();
}

public void delete()
{
    ttsbegin;
    element.numberSeqFormHandler().formMethodDataSourceDelete();
    super();
    ttscommit;
}

public void create(boolean _append = false,boolean extern = false)
{
    element.numberSeqFormHandler().formMethodDataSourceCreatePre();
    super(_append);
    if (!extern)
    {
        element.numberSeqFormHandler().formMethodDataSourceCreate();
    }
}

That's all..

AXAPTA get unit id for an item

Unit id for items aren't saving item table. There is a table named InventTableModule for unit id:


MyTable.UnitID  = InventTableModule::find(Sobj.ItemId,ModuleInventPurchSales::Invent).UnitId;

Second parameter is which module you looking for.

AXAPTA create sequential number

There is "Number Sequence class" for creating numbers for Axapta tables. But if you just want to create a "next number" function for just a string? Like "AB0001"->"AB0002". There isn't any built-in function in Axapta for that or I couldn't find. This is my number generator function:

Static str AutoNum(str Num)
{
    int i;
    int bas;
    str b;
    ;
    for (i=StrLen(num);i>=1;i--)
    {
        b=SubStr(num,i,1);
        if (b<"0" || b>"9")
        {
            bas=i+1;
            Break;
        }
        if (i==1)
            bas=1;
    }
    num=StrReplace(SubStr(num,1,bas-1)+
    Num2Str(Str2Num( SubStr(num,bas,StrLen(num) - bas + 1) )+1,
        StrLen(num) - bas + 1,0,1,0)," ","0");
    Return num;
}

AXAPTA modified method sometimes works twice

If combobox value selected with lookup and there is a data source refresh in method modified, modified method works twice. Another person faced this situation and unfortunately had not found a solution.
public void modified()
{
    ;
    super();
    info("111");
    salesLine_DS.research(true);
    salesLine_DS.refresh();
    info("222");
}
I found a solution for that and applined mine. I put a variable at class declaration method and:

public void modified()
{
    ;
    super();
    if (hasChanged) //for twice call bugfix.
        return;
    hasChanged=true;
    info("111");
    salesLine_DS.research(true);
    salesLine_DS.refresh();
    hasChanged=false;
    info("222");
}

AXAPTA multitable lookup

We can write a lookup and join two tables. So if we want  to show fields from second table at lookup list? Unfortunately Axapta's SysTableLookUp class cannot provide this feature. There is another class derived from SysTableLookUp named  SysMultiTableLookUp.

It's easy download and install it from this link. Sample is below:


public void Agreementlookup(FormControl _formControl, str _filterStr)
{
SMAAgreementTable SMAagreementTable;
Query query = new Query();
SysMultiTableLookup sysTableLookup;
QueryBuildDataSource queryBuildDataSource = query.addDataSource(tablenum(SMAAgreementTable));
QueryBuildDataSource qbds2;
QueryBuildRange qbr;
;

qbds2=queryBuildDataSource.addDataSource(tablenum(B_AgreementCustomerTable));
qbds2.relations(true);

qbr=qbds2.addRange(fieldnum(B_AgreementCustomerTable, num));

qbr.value(strfmt('((Num == "%1") && (AccountCode == TableGroupAll::Table)) || (AccountCode == TableGroupAll::All)',
QueryValue(salesTable.CustAccount)));

sysTableLookup = SysMultiTableLookup::newParameters(_formControl,query);
sysTableLookup.addLookupfield(fieldnum(SMAAgreementTable, AgreementId),1);
sysTableLookup.addLookupfield(fieldnum(SMAAgreementTable, AgreementDescription),1);
sysTableLookup.addLookupfield(fieldnum(SMAAgreementTable, ProjId),1);
sysTableLookup.addLookupfield(fieldnum(B_AgreementCustomerTable, AccountCode),2);
sysTableLookup.addLookupfield(fieldnum(B_AgreementCustomerTable, Num),2);

sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}

AXAPTA first bug

Today I discovered my first bug:

When classDeclaration method like below occurs that error:
public class FormRun extends ObjectRun{
    FormStringControl       lineAccountField;
    FormStringControl       lineAccountField2;
    NumberSeqFormHandler    numberSeqFormHandler;
    SMAAgreementId          agreementId;
}



When write like this, no error:
public class FormRun extends ObjectRun
{
    FormStringControl       lineAccountField;
    NumberSeqFormHandler    numberSeqFormHandler;
    SMAAgreementId          agreementId;
    FormStringControl       lineAccountField2;
}

29 Kasım 2011 Salı

AXAPTA get value sent by "Goto Main Table Form" button.


This blog copy of my turkish blog in english. I created this because unfortunately Google translator is so terrible with turkish translates even mines... :)
This value accessible by args().record() method, but in case of calling from different table fields extended by, it's a bit hard. You have to put case for every caller table or:


FormStringControl   callerControl   = SysTableLookup::getCallerStringControl(element.args());
;
info(callercontrol.text());



I found this code part from Yakup Kirisci's blog. It just already from standart forms, but I didn't know until see his blog. It worked good for me. Thanks to him...