jeudi 31 mars 2011

How to create a customized lookup on form

Override the lookup method on Formdatasource field(on which you want to show lookup) , and copy the following code to your method.
Comment the super() method in the lookup. 

public void lookup(FormControl _formControl, str _filterStr)
{
    SysTableLookup sysTableLookup; // systemclass to create //customlookup
    Query query;
    QueryBuildDataSource qbd;

    ;
    sysTableLookup = SysTableLookup::newParameters(
    tablenum(Dimensions),
    _formcontrol);

    // Construct query on the table,
    // whose records you want to show as lookup.

    query = new Query();
    qbd = query.addDataSource(tablenum(Dimensions));


    qbd.addRange(fieldnum(Dimensions, DimensionCode)).value(enum2str(SysDimension::Niveau_I));

    // add the fields to the lookup list
    sysTableLookup.addLookupfield(fieldnum(Dimensions,DimensionCode));
    sysTableLookup.addLookupfield(fieldnum(Dimensions,Num));

    // pass the query as parameter
    // system will show the records in the lookup
    // as per your query

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

mardi 29 mars 2011

How to close a form using X++

There are “only” 5 ways to close a form:
  • Close - close the form. Similar to the 'X' button.
  • CloseOK – close the form, and set the OK flag – called by the Commandbutton::Ok
  • CloseCancel – close the form, and set the Cancel flag – called by the Commandbutton::Cancel
  • CloseSelectRecord – close the lookup form, and set return record
  • CloseSelect – close the lookup form, and set return value

The below methods (note their names are in past-tense) are used to determine if or how a form was closed:
  • Closed – Returns true, if the form is no longer open
  • ClosedOK – Return true, if the form was closed by the user clicking ‘OK’
  • ClosedCancel – Returns true, if the form was closed by the user clicking ‘Cancel’

Finally, CanClose() is called before any of the close methods get called. If CanClose() returns false, the form is not allowed to close.

How to create a new Number sequence in a new module in Dynamics ax

in Number sequences in Axapta are a mechanism for generating unique numbers. These are generally used as a unique Id to identify a table record.
Every number sequence is linked to an ExtendedDataType inside Axapta. Therefore you will need to create separate datatypes for each number sequence which will be created. 

Follow this doc to know how to create a new Number Sequence

http://dynamicsdx.files.wordpress.com/2010/10/numbersequencex.doc

You can increment the new Number Sequence as following

static void ProformaIdSeq(Args _args)
{
    ExtendedTypeId id = TypeID2ExtendedTypeId(TypeId(Thy_ProformaId));

    NumberSeq num = NumberSeq::newGetNum(NumberSequenceReference::find(id));
    ;

    num.used();  // mark the number as used
    info(num.num());
}


Happy Daxing !