vendredi 26 novembre 2010

How to write values from DataBases tables in a text File in Dynamics AX

Here is the code :)

void f_txt(str path)
{
    String30                    m,m1,m2,m3,total;
    asciiio                     f;
    ;
    f = new asciiio(path,'w');

        m1 = "2563148";
        m2 = "000000254";
        m3 = "789645";
        f.outFieldDelimiter("");
        f.write(m1,"00",m2,"0000",3);
}

the path must be set as following : 

path = "C:\\ D0311001.A600.txt";

You get in your file text this value : 

 25631480000000025400003

Happy Daxing!

How to create a Lookup Form and use it as a formHelp Proprety of an ExtendedDataType in Dynamics AX

To create a Lookup Form in Dynamics AX, just create a form and add in the DataSources the table from which you want to get fields  : for example your need to get the emplId field from the table EmplTable: You can filter the field in the executeQuery method of this Table:

public void executeQuery()
{
    PayrollPaySlipJour                                    payrollpayslipjour;
    PayrollEmployee                                       payrollemployee;

    select  emplid from empltable exists join payrollpayslipjour join payrollemployee 
                                  where payrollpayslipjour.emplid== empltable.emplid
                                  && payrollemployee.EmplId == empltable.EmplId
                                  && payrollemployee.PayrollResignationClose == false;
}

In the init Method use this code: 

void init()
{
    Query   query = new Query();
    ;
    super();

    query.addDataSource(tablenum(empltable));

    this.query(query);
}

Then in the init method of the form use this code: 

void init()
{
    ;
    super();
    element.selectMode(EmplTable_EmplId);
}

Then add a Grid in the design of the from and add the fields you want besides of the field: EmplTable_EmplId whose Auto Declaration proprety must be set to yes .

Don't forget to set the following properties on the datasource, so that the form can not be used for editing:
       AllowCheck:    No
      AllowCreate:   No
      AllowDelete:   No
      AllowEdit:     No
      AutoNotify:    No
      InsertAtEnd:   No
      InsertIfEmpty: No
Additionally set for the design the following properties to make it look like a proper lookup:
         AlwaysOnTop:   Yes
      Frame:         Border
      HideToolbar:   Yes
      WindowType:    Popup

You can use it in the ExtendedDataType where you set the formHelp proprety to the name of this form.
Then whenever you call this field, you'll have this Lookup form displayed.
For example , I called it in a dialog and I got this:




You can always refer to http://www.axaptapedia.com/ Here is the link: 

http://www.axaptapedia.com/Lookup_Form

You can also define an EDT with a relation , when you set the EDT for a field you get your lookUp form.


Happy Daxing!

How and Why to use Field Groups in Dynamics AX

In Dynamics AX, we may need to use several fields together in a report or in a form we just call a Field Group containing these fields and we have all the fields.
Thus we create a Field Group in the table that will be used in the from or the report and drag all the fields we need.
Here is an example showing i the form the Filed Group and how it is created in the table:


jeudi 25 novembre 2010

How to create a dialog in a class and then returning the report in Dynamics AX

We can create the dialog usig the overrided method 'dialog' in the report and we can use separately a class that create the dialog , get the right values and then call the report.

In this class, we have theses methods:
 We must use :
Dialog: where we define the variables to use: 

Object dialog()
{
    DialogRunbase dialog = super();
    ;
    dialog.caption("@PAY5567");
    filetxt = dialog.addFieldValue(typeid(NoYes),rangePaytypeNum);
    filetxt.label("@Pay5325");
    Path  = dialog.addFieldValue(typeId(FileNameSave),rangePaytypeNum);
    return dialog;
}


We must use :
lastValueElementName: to call the appropriate report :
 
 identifiername lastValueElementName()
{
    return ReportStr(PayrollTransfer);
}



We must finally use :
main : to initialize and run the class for example : 

static void main(Args args)
{
    PayrolltransferReport                 payrolltransferReport ;
    ;
    payrolltransferReport  = new PayrolltransferReport ();

    if (payrolltransferReport .prompt() )
    {
        payrolltransferReport.run();
    }
}


We can use  
GetFromDialog: where we want to return the values entered: 

For example : 
public NoYes getFromDialog()
{
    ;
    showHolidaySection = NoYesCombo1.value();
    ChoosePrinter = NoYesCombo.value();
    return  super();
}

We can use 
Run : If we have some infologs or messages to display while filling in the dialog For example 

public void run()
{
    textbuffer  bufferyear;
    String30    buffertrimester;
    ;
    okcancel   = false;

    if(filetxt.value()==1)
    {
        if (path.value()!="" )
        {
            this.f_txt(path.value());
        //Le fichier text est crée
            Box::info("@Pay5323","info","...");
        }
        //L'emplacement est invalide !
        else
        {
            Box::info("@Pay5324","info","....");
            okcancel = true;
        }
    }

    else
    {
            okcancel = false;
    }

   // if(!okcancel)

    super();
}

Happy Daxing!

How to distinguish between the different layers of Microsoft Dynamics AX

Microsoft Dynamics AX Layered Architecture. You can think of the layered architecture of Microsoft Dynamics AX as the layers of an onion. Microsoft Dynamics AX begins with a SYS layer, in which the Core code is written. Nothing and no one can affect the code written in the SYS layer except for Microsoft Dynamics AX development itself. 

Surrounding the SYS layer is the GLS (global), layer. Microsoft development teams have built country specific localizations and other special customizations into these two layers.  Most localizations now exist in the SYS layer, which helps simplify implementations, especially across multi country deployements.  There are also GLS layers for Central and Eastern Europe, Iceland, India, Turkey, China, Brazil and Japan. 

In the BUS (business) and VAR (Value Added Reseller) layers, your chosen ISVs and implementation partners will build customizations that solve the specific needs of your business. The CUS (customer) layer is reserved for your own customizations, while every user at your site can customize their user experience using the USR (user) layer.


Dynamics AX 2009 consists of sixteen application object layers that contain all the elements you see in the AOT.
These layers can be looked at as an onion with multiple layers. In the middle is the core application in the SYS layer and the outermost layer is the user layer USR.
Therefore, when any application element is being executed the system will look at the outermost code layer first to see if there is any code for that element; if not, it peels a layer off the onion, and tries the next layer. When it hits a layer where the element exists, it will use the code from this layer, and will not continue to peel off layers to find code for that element in the innermost layers.

Layers with their description

SYS The standard application is implemented at the lowest level,
the SYS layer.The application objects in the standard
application can never be deleted.

GLS Country/region specific changes will be developed in GLS
Layer.For e.g as you all know that Tax structure differs
from country to country.So such localization functionality
can be developed in GLS layer.

HFX HFX is an application object patch layer reserved by
Microsoft for future patching or other updates.

SL1, SL2,or SL3 A layer where the distributor can implement
vertical partner solutions.

BUS When a business partner creates their own generic solution,
their modifications are saved in the BUS layer and the top-
level application objects are used.

VAR Value Added Resellers (VAR) can make modifications or new
developments to the VAR layer as specified by the customers
or as a strategy of creating an industry-specific solution.
Such modifications are saved in the VAR layer.

CUS The supervisor or administrator of an end user installation
might want to make modifications that are generic to the
company. Such modifications are saved in the CUS (CUStomer)
layer.

USR End users might want to make their own modifications, such
as in their reports.These modifications are saved in the USR
layer. 

How to assign a fixed value to a field in a datagrid of a form in Dynamics AX

When creating a new line in the datagrid , you want to assign a fixed value to a field from this datagrid,  you need to use the overrided method 'initValue' in the DataSource of your form as following for example: 

public void initValue()
{
    super();
    select firstonly PayrollPaytypeNum from payrollCompanyParameters;
    if (payrollCompanyParameters)
    {
        payrollPaytypeNum = payrollCompanyParameters.PayrollPaytypeNum;
    }
     PayrollCommonJournalTrans.PayrollPaytypeNum = payrollpaytypenum;
}

If you want to display in the grid specifics values you have just to override the method : executeQuery in you DataSource for example :
public void executeQuery()
{
    super();
    select empId from DropHoliday_1 join employee where employee.LogId == logId
                                     && employee.EmpId == DropHoliday_1.EmpId;
}


Happy Daxing!

lundi 22 novembre 2010

How to convert numeric amount into words from X++

Here's the code :)

display TempStr total_txt()
{
    PayrollPayTypeAmount           NetAmount; 
    Str                            TextValue;  
    ;
    NetAmount  =  PayrollPaySlipJour.DispNet ;
    TextValue  =  global::numeralsToTxt(NetAmount);
    return substr(TextValue, 5, strlen(TextValue)-4);
}

Happy daxing!

samedi 20 novembre 2010

How to use temporary table in reports in Dynamics AX

Here's the code :)
public boolean fetch()
 {
     boolean ret;
     ;
     this.queryRun().setRecord(tmpTableClass::populateTmpData());
 
     ret = super();
 
     return ret;
 } 
Resources:  
http://www.axaptapedia.com/Temporary_tables  
Happy Daxing!  

How to create and populate a Datatable in Dynamics AX

Here's the code :)

DataTable dt = new DataTable("Table1");  
dt.Columns.Add("c1");
dt.Columns.Add("c2");
dt.Columns.Add("c3");
DataRow dr = dt.NewRow();
dr["c1"]= "100";
dr["c2"]= "100";
dr["c3"]= "100";
dt.Rows.Add(dr);
dt.AcceptChanges();
dgView.DataSource = dt;
dgView.DataBind();

How to create a Word document from X++

Here's the code :)

COM wordApplication;
COM wordDocuments;
COM wordDocument;
COM wordRange;
;
wordApplication = new COM("word.application");
wordApplication.visible(TRUE);
wordDocuments = wordApplication.Documents();
wordDocument = wordDocuments.add();
wordDocument.saveas("c:\\YourDocument.doc");
wordDocument.activate();
wordRange = wordDocument.range(0,0);
wordRange.insertafter("Arijit Basu");
wordRange = wordDocument.range(6,19);

wordRange = wordDocument.range(11,26);
wordRange.italic(true);
wordDocument.save();
wordDocument.close();
wordApplication.quit();

Resources:  


Happy Daxing!

vendredi 19 novembre 2010

How to connect between report and RunBaseReport class in Dynamics AX

For example you want to make your report dynamic, you choose to display or not a programmable section or any other section of your design, or you choose the appropriate design...
 For example in you Runbasereport class, in the dialog method , you create a Combobox

public Object dialog()
{

    DialogRunBase      dialog = super();
    ;
    printJobSettings.setTarget(PrintMedium::Screen);
    dialog.addGroup("@SYS105079");
    dialog.addText("@PAY5597");
    NoYesCombo = dialog.addField(typeid("NoYes"));

    return dialog;
}

You get it value in the getDialogValue method : 

public NoYes getFromDialog()
{
    ;
    showHolidaySection = NoYesCombo.value();
  
    return  super();
}

And you return this value in order to use it :


public NoYes getShowHolidaySection()
{
    ;
    return showHolidaySection;
}

According to the value of this Combobox, you will display or not a programmable section.
You call this fonctionality in the fetch method of the report here.

 if (payslipJour.PayrollShowVacationAccount)
    {
        if ( myCaller.getShowHolidaySection() == NoYes::Yes)
        {
            this.execute(1);
        }
    }

Another good example to follow is found in the resources.

Happy Daxing!

How to call a report and a report's menuitem from X++

To call a report, use this code for example, if you need to call a report when clicking on a button :

void clicked()
{
    Args args = new args();
    ReportRun       reportRun;
;
    args.name(reportstr(PurchRequisitionDetails));
    reportRun = classFactory.reportRunClass(args);
    reportRun.init();
    reportrun.run();

    super();
}

 To call a report's menuitem , use this one :

MenuFunction    menuFunction;
;
menuFunction = new MenuFunction(reportStr(Cust), MenuItemType::Output);
menuFunction.create();
menuFunction.run();
 
Happy Daxing! 

How to call a form and a form's menuitem from X++

To run a form using classfactory use this code : 

       Args args = new Args();
    FormRun             formRun;
    ;
    args.name(formstr(salesTable));
    formRun = classfactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.wait();


To call a form's menuitem use this one :

     Args                    args;
    FormRun                 _formRun;
    ;
    args = new Args();
    args.parmObject(_formRun);
    _formRun =  new  MenuFunction(menuitemdisplaystr(Address),              MenuItemType::Display).create(args);
    _formrun.run();


Happy Daxing!

jeudi 18 novembre 2010

How to diplay the total of a column in a report in Dynamics AX

I. To diplay the total of a column (named ColumnA), you have to :
  1. Click on ColumnA and open its properties (Alt+enter)
  2. Modify the  SumAll to YES
  3. Create a new field (named ColumnASum) typed Sum
  4. In its properties, modify the dataFieldName to ColumnA
That's all, the sum of all lines will be diplayed in the field.

Remark : naturally the ColumnASum must be created outside and after the Body containing the ColumnA
For example, you put the ColumnA in the body of  a section group in a generated design and the sum of this column in the footer of the section group.

II. You can also calculate the sum of a column following another method : 
In the classdeclaration, declare a variable : sumnet   

In the executeSection method of the body you calculate the sum of your column : 


public void executeSection()
{
    sumnet=sumnet+tmpPayrolljournaldata_1.PayrollPaytypeAmount4;

    super();

Then, in the method of your report create a method that displays this variable :

Display Amount _SumNet()
{
    return SumNet;
}


In the Grand Total section : Footer of the generated design for example: 
create a field and set its DataMethod to  _SumNet .
this field calculates the sum of your column.


Resources
https://community.dynamics.com/product/ax/f/33/p/31623/54232.aspx
http://axassociate.blogspot.com/search/label/Report?max-results=3

Happy Daxing!

How To Set Positions of Sections and Controls on Reports in Dynamics AX

These are  standard classes with their method that are used to set the right positions for reports, sections and controls :

How to call different reports from one class in Dynamics AX

I added a Checkbox in the method : Dialog of the class,Via the Checkbox  I tried to manage that the
right report is choosen, when it is unchecked , I got the actual report when It is checked I call aonther similar class that returns the appropriate report.After the method prompt, I can get the value of  the checkBox in the dialog : true or false then according to the needs I can run the appropriate report.



jeudi 11 novembre 2010

How and when to use page breaks in Dynamics Ax reports

If you want a page break before a particular section, add an executeSection method and call element.newpage() before the call to super().









Else if you are displaying many pages in your report and you need  a section that change from a page to another according to your needs use page breaks:

How to choose between different types of designs in the same report according to user's needs in Dynamics AX

If you want in the same report  to build two different types of designs according to the user's need , you can create two designs or even more and to switch between  call "element.design(<design name>)" in "init" method of report.
For example according to the choice of the Printer, you will display the design called "EPSON" or " STANDARD"

How and when to use Macros in Dynamics AX

When your have values that can be changed, you don't have to get back to your code in classes, reports, forms .... Just make the change in your Macro and call it in your form, report, class ... whereever you need to use the value.
For example, when using the 'PayrollPayTypeNum' in your code, this may change, set all the values you use in the Macro:

























Declare this Macro in your class for example and call value you need to use:

  
tmpPayrollPaySlipTable.HeureSup175 = this.Amount (emplid, jobnum, #payrollpaytypenum24);

How to use colors in your report in Dynamics AX

For example, according to the value of 'payrollLocalAgreementCode' , you set the color of a Line, use this in the override method of the section : 'executeSection'.

You can use the job 'colors' to get the color you want , just choose the color and get its value:


For example for this color you
set the  value to 931170























mercredi 10 novembre 2010

How to select elements from a table that don't exist joining another table from X++

If you want to select for example from EmplTable all the Employees that don't exist in PayrollEmployee
, use this :
  select emplid from empltable notexists join payrollemployee
              where
empltable .EmplId == payrollemployee.EmplId ;

mardi 9 novembre 2010

How to Use a Programmable Section in Reports in Dynamics AX

We can use programmable sections to add any kind of customized information for example : sum of fields in the report .
To activate a programmable section, activate it explicitly with an element.execute(Number) statement. The Number must be specified in the ControlNumber property for the design section.

For example, I've created a prgrammable section calculating the sum of a column in dynamics ax .
To call this section , I add the method element.execute(1); in the fetch method after calling super() and before returning the result of the fetch

public boolean fetch()
{
    boolean ret;  
    ret = super();
    element.execute(1);
    return ret;
}

lundi 1 novembre 2010

How to Set a Combobox in a dialog Form in Dynamics AX

If you need to add a combobox in your dialog, you have to use  BaseEnums for example I created a BaseEnums : PayrollTrimester then use this method

 dialog.addField(typeid("PayrollTrimestre"));