jeudi 27 janvier 2011

How to create a specified field in a grid from X++

Create a method display in the DataSource TmpvendTable of your form and use this code for example:

Display string30 VendAccount(tmpvendtable v = tmpvendtable)
{
 
      VendTable             VendTable;
      string30        VendAccountExt;
      ;
 
      VendAccountExt = v.AccountNum + "aa";
      return VendAccountExt;
}

Then in the proprities of the filed set this method as a DataMethod.

Happy Daxing!

mercredi 26 janvier 2011

How to Use Temporary Table in a Form from X++

Follow this Link :

http://learnax.blogspot.com/2010/01/how-to-use-temporary-table-in-form.html

Happy Daxing!

How to export Data from a table to an Excel file from X++

Use this code :)

static void ExcelFile(Args _args)
{
    int                 i;
    InventTrans         Inventtrans;
    SysExcelApplication excelApp;
    SysExcelWorkbooks   books;
    SysExcelWorkbook    book;
    SysExcelWorksheets  sheets;
    SysExcelWorksheet   sheet;
    SysExcelCells       cells;
    SysExcelCell        cell;
    ;
    i=2;
    excelApp = SysExcelApplication::construct();
    books    = excelApp.workbooks();
    book     = books.add();
    sheets   = excelApp.worksheets();
    sheet    = sheets.itemFromNum(1);
    sheet.name("XMC");
    cells    = sheet.cells();
    cell     = cells.item(1,1);
    cell.value("ItemId");
    cell     = cells.item(1,2);
    cell.value("StatusIssue");
    cell     = cells.item(1,3);
    cell.value("TransType");
    cell     = cells.item(1,4);
    cell.value("CostAmountPosted");
    cell     = cells.item(1,5);
    cell.value("Qty");
    while select ItemId, StatusIssue, TransType, CostAmountPosted, Qty from Inventtrans 
    {
      cells    = sheet.cells();
      cell     = cells.item(i,1);
      cell.value(Inventtrans.ItemId);
      cell     = cells.item(i,2);
      cell.value(Inventtrans.StatusIssue);
      cell     = cells.item(i,3);
      cell.value(Inventtrans.TransType);
      cell     = cells.item(i,4);
      cell.value(Inventtrans.CostAmountPosted);
      cell     = cells.item(i,5);
      cell.value(Inventtrans.Qty);
      i++; 
    }
    excelApp.visible(true);
    book.saveAs("C:\\xmc_ExelFile");

}

Happy Daxing!

How to print a report to printer directly from X++

If you want to print a report to printer directly without prompt/dialog showing query use this code:

Args ArgList;
ReportRun rptJobOrder;
;
ArgList = new Args(reportStr(MyReport));

rptJobOrder = new ReportRun (ArgList);
rptJobOrder.design().caption('MyReport');
rptJobOrder.query().interactive(false);

rptJobORder.args().parm('my parameters');
rptJobORder.setTarget(printMedium::Printer);
rptJobOrder.run();

Happy Daxing!

How to fill a temporary table using a form and display its data in a report called from this form using X++

Create a form with two buttons one for inserting Data ' Insert' and the second for calling the report 'Print' .
Create the method "populate" in your form and fill the temporary table with the fileds you want to display in the report.
Override the clicked method for the button ' Insert' and use this code for example to fill the temporary table:

void clicked()
{
    super();
          TmpTestTable.setTmpData(element.populate());
          TmpTestTable_ds.research();
}

To print the report using this data, we need an intermediate class that extends RunBaseReport we create these following methods : first of all a constructor


void new(TmpTestTable _TmpTestTable,EmplId _emplId, PayrollJobStartDate _startDate,PayrollJobEndDate _endDate,PayrollIncrement _payrollIncrement)
{
    ;
    TmpTestTable            = _TmpTestTable;
    EmplId                  = _emplId;
    PayrollJobStartDate     = _startDate;
    PayrollJobEndDate       = _endDate;
    PayrollIncrement        = _payrollIncrement;
    super();
 a method that returns the populated temporary table
 
TmpTestTable populate(EmplId _EmplId,PayrollJobStartDate _StartDate, PayrollJobEndDate _EndDate,PayrollIncrement  _payrollIncrement)
{
    return TmpTestTable;
}

 a method that calls the report

identifiername lastValueElementName()
{
    return ReportStr(TestReport);

The prompt method to prompt the query of the report with data

public boolean prompt()
{
    boolean ret;
    ;
    ret = super();

    this.queryRun().setRecord(this.populate(EmplId, payrollJobStartDate, payrollJobEndDate, payrollIncrement));

    return ret;

Finally in the print button used to call the report use this code: 

void clicked()
{
    TestClass               TestClass ;
    ;

    super();

    TestClass = new TestClass(TmpTestTable,TmpTestTable_EmplId.valueStr(), TmpTestTable_StartDate.dateValue(),TmpTestTable_EndDate.dateValue(),TmpTestTable_PayrollIncrement.value());

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

Resources:
http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/CommunityServer-Components-PostAttachments/00-01-72-59-34/Application-Fundamentals.ppt

Happy Daxing! 

lundi 24 janvier 2011

How to calculate the difference between two dates and set the value automatically in a field of a grid after choosing two values from X++

You have a grid where you can select the StartDate and the EndDate of  the vacation, and you have a field for the calculation of the differnce in days between these two fields:








You can override the method leave of the grid  and use this code for example to calculate the diffrence:
public boolean leave()
{
    Boolean                ret;
    StartDate              inputDate;
    EndDate                refDate;
    ret = super();

    inputDate = str2Date(strFmt("%1",DropHoliday_1.StartDate), 123);
    refDate = str2Date(strFmt("%1",DropHoliday_1.EndDate), 123);
    DropHoliday_1.DaysHoliday=intvNo(refDate, inputDate, intvScale::YearMonthDay);
    return ret;
}

Happy Daxing!

lundi 10 janvier 2011

How to pass parameters between class and report

Suppose that you have a RunBase class that call for a report .
You can use methods and parameters from this class into your report.
then in the init method of your report use this :

public void init()
{
   // NoYes test;
    super();
    myCaller = this.args().caller();

    if (myCaller)
    {
        if (myCaller.parmPayrollJobTable())
        {
            if(!myCaller.parmPayrollJobTable().PayrollClosed)
            {
                //BP Deviation Documented
                payslipJour.setTmp();
                //BP Deviation Documented
                payslipTrans.setTmp();
                payslipJour.setTmpData(myCaller.parmTmpPayslipJour());
                payslipTrans.setTmpData(myCaller.parmTmpPayslipTrans());
                thisEmplQueryRun = new QueryRun(myCaller.queryRun().query());
            }
            emplSet = myCaller.parmEmplSet();
        }
    }
    else
    {
        throw error("@PAY3089");
    }
}

 Happy Daxing !

How to pass values between form and report

Here is for example the code of the button that calls the report:

void clicked()
{
    Args     args;
    ReportRun          reportRun;
    ;
    super();
    args = new Args();
    args.name(Reportstr(HistoryHolidays));
    args.parm( LogId  );
    reportRun = classfactory.reportRunClass(args);
    reportRun.init();
    reportRun.run();
    reportRun.wait();
    args.parmObject( args );
}

in the init method of your report  try this:

public void init()
{
    if( element.args() )
    {
        logId =  element.args().parm();
    }
     super();
}

then you can use this parameter in your report form example: 

public void executeSection()
{
    ;

    if  ( employee_1.LogId == logId)
    {
        emplId = employee_1.empId;
        super();
    }
    if ( logid == "1")
    {
        emplId = DropHoliday_1.EmpId;
        super();
    }

}

Happy Daxing !

How to pass values between two forms

Lets suppose that we have FormA which calls FormB and passes some parameters to that form. 
For the method clicked button in formA that calls formB we can use this code: 

void clicked()
{
    LogId            login0;
    Password         password0;
    Fonctions        Fonction;
    Args             args;
    FormRun          formRun;
    Integer          emplId;

    ;

    super();
    args = new Args();
    login0 = login.valueStr();
    password0 = password.valueStr();

    select firstOnly  EmpId,title, logid, password from employee where employee.logid == login0 && employee.password == password0;

    emplid = employee.EmpId;

       if (employee.title == Fonction::None)
       {
            box::info("Wrong login or password");
       }
       else
       {
            if (employee.title == Fonction::Employee)
            {
                args.name(formstr(HistoryHolidays));
            }
            else
            {
                args.name(formstr(ConfirmHoliday));
            }

            args.parm( login.text()  );
            formRun = classfactory.formRunClass(args);
            formRun.init();
            formRun.run();
            formRun.wait();
       }
       args.parmObject( args );

}
then in the init method of the formB we have to use this:

public void init()
{
    ;
    if( element.args() )
    {
        logId =  element.args().parm();
    }
    super();
}

Thus, you can use the parameter LogId that you gets from FormA in the FormB.

Resources :
Happy Daxing!

mercredi 5 janvier 2011

How to install Microsoft Dynamics AX

Follow this link to  watch a video showing steps of installing Microsoft Dynamics AX .

Install Microsoft Dynamics AX

Happy Daxing!

What is the folder structure in Dynamics AX4

The installation of Dynamics AX 4 consists of three main parts:
  1. Server installation
  2. Client installation
  3. Application installation
The path to the installation folders may be changed in the Dynamics AX Setup Wizard. However, if the default paths are used and all three parts are installed on the same machine, then the folder structure will look like below:



Blog Image

Figure 1. Microsoft Dynamics AX 4 folder

Folder description:
  • Application\Appl - contains the application files (business logic) and label files (.ald) for each language. The main application file is Ax<Layer ID>.aod containing the entire application (X++) code per layer.
  • Application\Appl\Standard\Db - MSDE database files.
  • Application\Appl\Standard\Tmp - Temporary files generated by the system.
  • Application\Appl\Standard\Old - during an upgrade the old application files are copied here.
  • Client\Bin - executable, dll files used on the client side and language dependent text files (.ktd) used by executables.
  • Server\DynamicsAX\Bin - executable, dll files used on the server side and language dependent text files (.ktd) used by executables. 
Happy Daxing !

    mardi 4 janvier 2011

    How to Enable/Disable fields in a dialog

    You can enable events for your dialog objects by overriding the method dialogpostRun:

    public void dialogPostRun(DialogRunbase _dialog)
    {
        ;
        super(_dialog);

        // allow to call the event methods of this class (e.g. fld900_1_modified() method)
        _dialog.dialogForm().formRun().controlMethodOverload(true);
        _dialog.dialogForm().formRun().controlMethodOverloadObject(this);
    }

    Then you can create event methods on your dialog fileds like fld900_1_modified() where you can address other components in the dialog, and modify their properties.


    public boolean fld900_1_modified()
    {
        FormStringControl   control = dialog.formRun().controlCallingMethod();
        boolean             isFieldModified;
        ;

        isFieldModified = control.modified();

        // every time the employee id is changed, update the employee name
        if(isFieldModified)
        {
            dlgFldEmplName.value(EmplTable::find(control.text()).Name());
        }

        return isFieldModified;
    }

    You will also need to make sure that the control “Employee ID” gets the same control ID as used in the event method name (). This should be done at the time of adding the control to the dialog. Please see below:

    protected Object dialog(DialogRunbase _dialog, boolean _forceOnClient)
    {
        ;
        dialog = super(_dialog, _forceOnClient);

        // Add a new field by explicitly specifying the field id.
        // This field id is used to create the field event methods (e.g. fld900_1_modified()).
        dlgFldEmplId = new DialogField(dialog, typeid(EmplId), #dlgFlgEmplIdFieldNo);
        dialog.addCtrlDialogField(dlgFldEmplId.name());

        dlgFldEmplId.init(dialog);
        dlgFldEmplId.label("@SYS81251");
        dlgFldEmplId.helpText("@SYS81251");
        dlgFldEmplId.value(emplId);

        // verify that the field name generated by the system is correct
        if(dlgFldEmplId.name() != #dlgFlgEmplIdFieldName)
        {
            throw error(strfmt("@SYS79285", dlgFldEmplId.name(), #dlgFlgEmplIdFieldName));
        }

        // Add a new field and let the Dialog framework to do all the work by assigning the field id and initializing the control since there are no event methods for that field.
        dlgFldEmplName = dialog.addFieldValue(typeid(EmplName), emplName, "@SYS54564", "@SYS54564");
        dlgFldEmplName.enabled(false);
       

        return dialog;
    }



    Then you can get the value of fields using this method :

    public boolean getFromDialog()
    {
        boolean ret;

        ret = super();

        // get the values from the dialog in order to save them in SysLastValue (using pack() method)
        emplId      = dlgFldEmplId.value();
        emplName    = dlgFldEmplName.value();

        return ret;
    }

    verify whether a correct employee id has been specified


    public boolean fld900_1_validate()
    {
        FormStringControl   control = dialog.formRun().controlCallingMethod();
        ;
        // verify whether a correct employee id has been specified
        return EmplTable::checkExist(control.text());
    }


    The pack and unpack methods are used as following:


    public container pack()
    {
        // pack the employee id and employee name and save them in SysLastValue
        return [#CurrentVersion, #CurrentList];
    }

    public boolean unpack(container packedClass)
    {
        boolean  ret;
        Integer  version = conpeek(packedClass,1);
        ;

        switch (version)
        {
            case #CurrentVersion:

                // get the employee id and employee name values from the container that has been saved in the SysLastValue record
                [version, #CurrentList] = packedClass;
                ret = true;
                break;

            default:
                ret = false;
        }

        return ret;
    }



    Finally, in the main method :

    static void main(Args args)
    {
        SETutorialDialogControlEvent  seTutorialDialogControlEvent = SETutorialDialogControlEvent::construct();
        ;
        // show the dialog
        if (seTutorialDialogControlEvent.prompt())
        {
            // if OK is pressed, run some code (in that case, run() method should be overriden in the current class)
            seTutorialDialogControlEvent.run();
        }
    }

    Where SETutorialDialogControlEvent is defined as following:

    public static SETutorialDialogControlEvent construct()
    {
    return new SETutorialDialogControlEvent();
    }
    As you can see the macro #dlgFlgEmplIdFieldNo is used to assign the ID to the dialog control.  
    Overriding the event methods (e.g. modify, validate, selectionChange) on dialog controls is not as straight forward as it is on form controls.

    Happy Daxing! 

    lundi 3 janvier 2011

    How to create and use Wizard

    To create Wizards, refer to this link :

    To use methods of Wizard Classes : 

    To use Wizards, have a look on this example :


    Happy Daxing !

    How to pass values from form to report

    1. Make the report as Interactive.

    image

    2. Create Method initFromCaller and pass the args to it.  

    image
     

     
    3. Set the report caption (it will appear in dialog)/. 

    image

    4. The Method initFromCaller.
    Method initFromCaller
    public void initFromCaller(Args _args)
    {
    InventJournalTable inventJournalTable;
    QueryBuildDataSource qbds;
    ;
    if (_args.caller())
    {
    if (! _args.record().recId)
    throw error(strfmt("@SYS22338",funcname()));
    switch (_args.dataset())
    {
    case tablenum(InventJournalTable):
     
    inventJournalTable = _args.record();
    if (inventJournalTable.journalType != InventJournalType::Transfer)
    throw error(strfmt("@SYS23396",funcname()));
     
    break;
    default:
    throw error(strfmt("@SYS23396",funcname()));
    }
    }
     
    if (true || inventJournalTable.journalId) 
    {
    qbds = element.query().dataSourceTable(tablenum(InventJournalTrans)); 
    SysQuery::findOrCreateRange(qbds, fieldnum(InventJournalTrans, journalId)).value(inventJournalTable.journalId);
    SysQuery::findOrCreateRange(qbds, fieldnum(InventJournalTrans, journalType)).value(queryValue(InventJournalType::Transfer)); 
    }
    }
    Happy Daxing !

    HAPPY NEW YEAR 2011