jeudi 30 décembre 2010

How to control "Some Controls" in a form depending on some values in the rows from X++

I would like to show how we can change the status, the property of any control that depends in some values of the fetched data from th DataSource

example:  
I want to disable BUTTON1 if the type of the record is "100"
























Here are the steps you need to follow :
  1. Make the button AutoDeclared:
  2. Overload the method “Active” from the datasource methods.
  3. Make your condition.
For example in the method Active of your DataSource you can write this code

public int active()
{
int ret;
 
ret = super();
 
if(Dimensions.DimensionCode==SysDimension::Purpose)
{
Button.enabled(true);
} 
else
{
Button.enabled(false);
}
 
return ret;
}

Happy Daxing !

How to get and edit controls in a forms from X++

There are two ways to do it, as usual there is a hard and an easy way.

1- Declare the Control:
The very will know way is the easy way, that you set the control as "AutoDeclaration" to YES , but unfortunately this way has a serious drawback.

image











The "AutoDeclaration" makes the system slower for couple of reasons.

2- Define the control programmatically:
This is the hard way, but it performs better, since it does apply only one call.

Create the method in my case it is an event overwritten method, and I want to access "VendPurchOrderJour_InvoiceAccount"

image











Here is the Code.
void clicked()
{
FormDateControl         dt;        //Form Control Type
FormStaticTextControl   st;         //Form Control Type
;
super();
//Where “VendPurchOrderJour_InvoiceAccount” is the Control Name
dt = element.design().control(control::VendPurchOrderJour_InvoiceAccount);
st = element.design().control(control::MyStaticText);
st.text(dt.valueStr());
}

About the Form Control Type, here the list of all form types *:

Form control type
Class
ActiveX
Animate
Button
ButtonGroup
CheckBox
ComboBox
CommandButton
DateEdit
Grid
Group
GuidEdit
HTML
Int64Edit
IntEdit
ListBox
ListView
MenuItemButton
MenuButton
Progress
RadioButton
RealEdit
StaticText
StringEdit
Tab
TabPage
FormTabPageControl
Table
TimeEdit
Tree
Window

Happy Daxing !

How to pass parameters to the report from Output Menu Item from X++

To do so : 

1. Define Parameters in the Menu Item Properties:
image










2. Read the Parameters in any part of the report:
display Name reportName()
{
str callerParameter;
;
callerParameter=element.args().parm();
return callerParameter;
}
Happy Daxing !

How to generate default value of some controls in form (when creating new record) from X++

To do so you have to create initValue() method in the tableand write in your code for example

image
public void initValue()
{
MobobaGroup mobobaGroup;
;
 
select maxof(GroupCode) from mobobaGroup;
this.GroupCode = mobobaGroup.GroupCode + 1;
super();
}
 

mercredi 29 décembre 2010

How to create a dialog when clicking a button in a form from X ++

To do this follow this example in the Clicked method of the Button:

 void clicked()
{
     InventDimCombination            InventDimCombination;
     Args                    args;
     FormRun                 _formRun;
     ;
     element.design().controlName("CustVendExternalItem_ItemId");



     dialog = new  Dialog();
     dialog.caption("@BFP2160");
     dialog.addGroup("@BFP2160");
     Vendrelation = dialog.addField(typeId(CustVendRelation));
     ExternalItemId = dialog.addField(typeId(ExternalItemId));

     if (dialog.run())
     {

     ttsbegin;
     while select forupdate custVendExternalItem
                                where
                            custVendExternalItem.ItemId == itemid
            custVendExternalItem.delete();
     ttscommit;

     custVendExternalItem_DS.refresh();
     custVendExternalItem_DS.research();
     custVendExternalItem_DS.reread();
         while select ItemId, inventDimId from InventDimCombination where InventDimCombination.ItemId == itemid
         {

            custVendExternalItem.ModuleType             = moduleType;
            custVendExternalItem.CustVendRelation       = custVendRelation;
            custVendExternalItem.ItemId = itemid;
            custVendExternalItem.inventDimId  = InventDimCombination.inventDimId;
            custVendExternalItem.CustVendRelation = Vendrelation.value();
            custVendExternalItem.ExternalItemId = ExternalItemId.value();
            custVendExternalItem.insert();
         }


         custVendExternalItem_DS.refresh();
         custVendExternalItem_DS.research();
         custVendExternalItem_DS.reread();
     }

     super();

}

Happy Daxing ! 

How to add a field that you created in a grid from X++

If you want to add a field that doesn't exist in the table and you created it.
Write the Display method that returns this field in the methods of the table, then, set this method in the DataMethod proprety of this field instead of the field name, as shown in the following example:


















Happy daxing ! 

mercredi 15 décembre 2010

How to loop through the highlighted records in a grid from X++

Here is the code :)

LedgerTable ledgerTableLocal;
    ;

    ledgerTableLocal = ledgerTable_ds.getFirst(true) ?
ledgerTable_ds.getFirst(true) : ledgerTable;

    while(ledgerTableLocal)
    {
        info (ledgerTableLocal.AccountNum);

        ledgerTableLocal = ledgerTable_ds.getNext();
    }

 

Happy Daxing!

How to use the value of a CheckBox which is not a field in a table from X++

To do this you have to use the overrided method "modified" of this field.

Then you can write your code like following: 

public boolean modified()
{
    boolean                   ret;
    PayrollEmplrate           PayrollEmplrate;
    ;

    ret = super();

    element.design().controlName("Heade_family");

    if ( Heade_family.value() == 0)
    {
        // write your  instructions here
    }
    else
    {
        // write your  instructions here
    } 
    return ret;
}

Happy Daxing!

How to enable a field in case of multiple selection in a grid from X++

If you have TabPages in your form you can use this functionality in the overrided method "pageActivated"

For example in your TabPage you have a checkBox to disable in case of multiple selections.

then you can use this code for example
 c = 1;
 Heade_family.enabled(true);
      for(Employee = PayrollEmployee_ds.getFirst(true)?PayrollEmployee_ds.getFirst(true):PayrollEmployee_ds.cursor();Employee;Employee=PayrollEmployee_ds.getNext())
    {
         if(c>1)
         {
              Heade_family.enabled(false);
              break;
         }
        else
         {
              // write your code here
         }

       c++;

    }

Happy Daxing !

Where to watch Dynamics AX videos

I you want to enjoy very instructives videos concerning Dynamics AX, follow this link :


Enjoy it !

mardi 14 décembre 2010

How to filter records in a form from X++

Some time you need to show filtered records on the form (adding ranges to form datasource).  you just need write some code similar to this :

this.query().dataSourceName("CustTable").addRange             (fieldnum(CustTable,Currency)).value(queryvalue(‘USD’)); 

Follow this Link : 

http://dynamics-ax-live.blogspot.com/2010/03/how-to-filter-records-in-form-by-code.html 

Some time you need to use expressions or if you need OR clause in the query. Support of expressions is very good to implement the complex queries containing some complex joins and conditions. if you need to implement OR clause then again you need to use the expressions. If you add ranges to two different fields then it default supports the “And &&” clause, the “OR ||” clause is only supported if you add ranges to same field with different value. In all other cases we need to use the expressions to implement the OR clause. For details on implementing the expressions

See this Link : 
 http://www.axaptapedia.com/Expressions_in_query_ranges

Happy Daxing !

How to change company from X++

The changeCompany statement is used to alter the database settings to another (separate) company. The syntax of the statement is:
changeCompany ( Expression ) Statement
Here is the code

static void main()
{
    CustTable custTable;
    ;
    // Assume that you are running in company 'aaa'.
    changeCompany('bbb') // Default company is now 'bbb'.
    {
        custTable = null;
        while select custTable
        {
            // custTable is now selected in company 'bbb'.
        }
    }
    // Default company is again set back to 'aaa'.

    changeCompany('ccc') // Default company is now 'ccc'.
    {   
        // Clear custTable to let the select work
        // on the new default company.
        custTable = null;
   
        while select custTable
        {
            // custTable is now selected in company 'ccc'.
        }
    }
    // Default company is again 'aaa'.
}

Happy Daxing !

How to validate only numbers or caracters from X++

Here is the code :)

static void TextBuffer_regularExpression(Args _args)
{

    TextBuffer txt = new TextBuffer();
    str msg = "98797897";
    ;


    txt.setText(msg);
    txt.regularExpressions(true);   // activate regular expr in search


     // Regular expression to validate only digits
    
if (txt.find("^[0-9]+$"))
    {
        info("string contains only numbers");
    }

}

If you want to validate only chars just use [a-z] instead of [0-9]

Happy Daxing! 

How to get Ranges / Criteria from Query and count records from X++

Here is the code illustrating how to get Ranges / Criteria from the run_time query dialog

static void Query_getRanges(Args _args)
{
    Query                   query = new Query();
    QueryRun                queryRun;
    QueryBuildDataSource    qbd;
    CustTable               custTable;
    QueryBuildRange         range;
    int                     cnt, i;
    ;

    qbd = query.addDataSource(tablenum(CustTable));

    queryRun = new QueryRun(query);

    queryRun.prompt();   // To Prompt the dialog
    cnt = queryRun.query().dataSourceTable(tablenum(CustTable)).rangeCount();  // number of ranges in Query 
 info(strfmt("Total Records in Query %1",SysQuery::countTotal(queryRun))); // number of records in Query
// showing query description
   
for (i=1 ; i<=cnt; i++)
    {
        range = queryRun.query().dataSourceTable(tablenum(CustTable)).range(i);
        info(strfmt("Range Field %1, Value %2",range.AOTname(),range.value()));
    }
//showing  data from the datasource according to the query
   
while (queryRun.next())
    {
        custTable = queryRun.get(tablenum(CustTable));
        info(strfmt("Customer %1, Name %2",custTable.AccountNum, custTable.Name));
    }
}

 



















































Happy daxing!

lundi 13 décembre 2010

How to add an AOT query to SysQueryForm from X++

Here is the code :)

SysQueryRun queryRun = new SysQueryRun(queryStr(TestQuery));
queryRun.form(formstr(SysQueryForm));
queryRun.title(‘Select a record’);
queryRun.prompt();

Happy Daxing ! 

How to use Advance DataTypes in Dynamics AX from X++

There are many :

1.List Class
2.Map Class
3.Set Class
4.Container
5.RecordSortedList
6.RecordInsertList
7.Temp table.

Here is a full document describing each DataType

Advance DataTypes

Happy Daxing !

How to combine two lists in Dynamics AX from X++

Here is an example :)

static void ListSample(Args _args)
{

    List list1  = new List(Types::Integer);
    List list2  = new List(Types::Integer);
    List combinedList  = new List(Types::Integer);
    int  i;
    ;
   
    for(i=1; i<6; i++)
    {
        List1.addEnd(i);
    }
   
     for(i=6; i<11; i++)
    {
        List2.addEnd(i);
    }
   
    combinedList = List::merge(list1, list2);
   
    print combinedList.toString();
    pause;

}

Happy Daxing!

How to use Data List Structure in Dynamics AX

 For example, this code shows how to fill a list with elements and some functions associated :

static void ListSample(Args _args)
{
    List list = new List(Types::Integer);
    Enumerator en ;
    ;
    list.addEnd(333333); // add the value at last
    list.addEnd(111111);
    list.addEnd(222222);
    en = list.getEnumerator();
   
    print list.elements(); //"print number of element"
  
    while (en.moveNext())
    {
        print en.current(); //display each element of the list
    }
   
    print list.toString(); // list : <333333, 111111, 222222>
    print list.definitionString(); // defintion of the list for example : List of Int
    pause;
}


Links : 
http://msdn.microsoft.com/en-us/library/aa498818.aspx

Happy Daxing!

How and Which kernel Functions to use in Dynamics AX

Here are the Links :)


Happy Daxing! 

vendredi 3 décembre 2010

How to find the max/min of a column in a table from X++

Here is the code :)

static void Maximum(Args _args)
{
     Amount                             taxablesalary, maxim;
     PayrollpayTypeTransaction          payrollPayTypeTransaction ;
     Container                          c;
     PayrollIncrement                          i;
      #macrolib.PayrollpaytypeNum
      ;
    
    
     while select payrollpaytypeamount from payrollPayTypeTransaction where payrollPayTypeTransaction.PayrollPaytypeNum == #PayrollPaytypeNumC3
        {
        c = c + [ payrollPayTypeTransaction.PayrollPaytypeAmount ];
        }
       
        maxim = conpeek ( c ,1);
        for(i=1; i< conlen(c)+1 ;i++)
        {
              maxim = max( maxim, conpeek ( c, i+1));
              info(conpeek(c, i));
        }
}
The same with the min using min function


Well we can do this using Array DataType also 
 Here is the link :
 http://kashperuk.blogspot.com/


Happy Daxing :) !

How and When to use basic methods of tables from X++

The basic methods are executed when the table is used, for example, when we introduce, updated or erased data.

Caption

is the head of a form. The text is generated from the properties of the table.

Clear

the fields of the present registry erase (they have values NULL).

Delete

a registry is eliminated.

HelpField

the text of aid of a field is in the state bar, for example when we happened to the following field in a form.

InitValue

It initializes the fields of a registry just created.

Insert

a new registry in the table is introduced.

Merge

two registries are united or combined.

PostLoad

a registry is loaded.

RenamePrimaryKey

renombra the primary key of the table.

ReRead

a registry is reread.

ToolTipField

the leader of the mouse is located in a field of a form.

ToolTipRecord

one is going away to show an advice for the present field. The super method () makes a call to Caption.

Update

before modifying an existing registry.

ValidateDelete

one is going away to erase a registry.

ValidateField

a field give ins, for example when we jumped to the following field of a registry.

ValidateWrite

before writing a registry in the data base.

Happy Daxing!