Saturday, July 30, 2011

How to disable the “Setup” option for the Forms in the Axapta in security keys for the users

How to disable the “Setup” option for the Forms in the Axapta in security keys for the users….
Go to
Administration --- > Setup --- > User Groups --- > Create a new user Group and add the User to the newly created used group as shown in the screen shot



Click on the Button “Permissions”, now in the User Group permissions Form go to Permissions Tab, there able to see the tree structure of all the modules
Here to go
Administration --- > Miscellaneous --- > select the Form Personalization --- > and give No Access as shown in the below screen shot.


Now attach this User group to User in the Administration --- > Users Form for which users want to disable the setup option in the forms…

Monday, July 25, 2011

How to Configure the Batch jobs…

Batch jobs are required to perform the particular/defined set of action in the system in the regular intervals of time defined accordingly…
In AX there were the existing batch jobs, we can use them accordingly to your use….
Let say for example,
In the Employee master, employee status needs to change accordingly…
i.e. if employee is going on leave one week after, but the leave is entered on the current date, so employee status need to be changed on the day of the leave.
Once the employee is back from the leave, it is should be retained back to original status accordingly..
So in this case of scenario’s we can have a batch job which run basis on the interval defined and changes the status accordingly…
To write a batch job...
Create a new class and it should extend from “RunBaseBatch” from the standard AX.
Class EmployeeStatusChange extends RunBaseBatch
{
}

And having the logic as per accordingly…
After creating the class, create the action menu item for the Class.
Setup;
In Administration --- setup --- open the Server Configuration form


Is Batch Server check box needs to be checked – this indicates the batch job need to be executed on which AOS instance.

In Administration --- setup --- open the Batch Group form


Here create a new Batch Group and in the Batch servers tab selected the server on which this job needs to be scheduled.

Now open the Action menu item created for the class,then

Here attach the batch job created in the above step , mark the Batch processing checkbox and click the Recurrence button there need to be defined when the job needs to be started, and what interval need to processed..
In the alerts button, email alerts can be defined.

Once the Batch job is scheduled it is being queued in the Batch Jobs list..In Basic – Inquiries – Batch Job, here the scheduled batch can be found.

Sunday, July 17, 2011

How to create ‘New Number Sequence’ if added new module in AX.

How to create ‘New Number Sequence’ if added new module in AX.
I have created a new Module “Payroll”
Setp1:
Need to create a new element in the baseenum “NumberSeqModule” as “Payroll” .The name should be baseenum should be the Module name.
Step2:
The field which need to be generated as number sequence it should be as extended data type.So create a extended data type and use this in the table.
Step3:
Create a new class as per module name as follows “NumberSeqRefernce_Payroll”
Add the following methods
Class NumberSeqRefernce_Payroll extends NumberSeqReference
{
}

public static client server NumberSeqModule numberSeqModule()
{
    return NumberSeqModule::Payroll;
}

protected void loadModule()
{
    NumberSequenceReference numRef;
    ;

    numRef.dataTypeId                     = typeId2ExtendedTypeId(typeid(EmpId));
    numRef.configurationKeyId       = configurationKeyNum(payroll);
    numRef.referenceHelp                = literalStr("Unique Key for Employee identification.The key is used when creating the Employee");
    numRef.wizardContinuous         = true;
    numRef.wizardManual                 = NoYes::No;
    numRef.wizardAllowChangeDown    = NoYes::No;
    numRef.wizardAllowChangeUp      = NoYes::No;
    numRef.wizardHighest            = 999999;
    numRef.sortField                = 1;

    this.create(numRef);
}


Step4:
To get the new module number sequence in the Basic > Setup > Number sequences > Number sequences, add the following code in the “NumberSeqReference” class methods

In Construct () method add the following line of code…
case (NumberSeqRefernce_Payroll::numberSeqModule()) : return new NumberSeqrefernce_Payroll(_module);

 In the moduleList() method….
moduleList += NumberSeqrefernce_Payroll::numberSeqModule();

Step5:
Go to Basic > Setup > Number sequences > Number sequences there click the Wizard button in the form & click the Next button.
 On the next screen, the number sequence for the Module “Payroll” will be shown,go further and finish the wizard.
After finishing the wizard select newly created number sequence in Number sequences form and go to General Tab and check the continuous check box

Step6:
Design the form and add the following code in the form
In Form
In Class declaration declare the
NumberSeqFormHandler numberSeqFormHandler;

Added the following method
NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
    {
        numberSeqFormHandler = NumberSeqFormHandler::newForm(EmployeeTable::numRefEmpId().NumberSequence,element, EmployeeTable_ds, fieldnum(EmployeeTable, EmpId));
    }
    return numberSeqFormHandler;
}

In the form DataSource Level added following methods

public void create(boolean _append = false)
{
    element.numberSeqFormHandler().formMethodDataSourceCreatePre();

    super(_append);

    element.numberSeqFormHandler().formMethodDataSourceCreate();
}
public void delete()
{
    element.numberSeqFormHandler().formMethodDataSourceDelete();

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

Monday, July 11, 2011

Adding table methods in the form lookup method.....

Adding the table level methods in the form lookup as the table fields...

public void lookup(FormControl _formControl, str _filterStr)
{
    SysTableLookup              sysTableLookup;
    Query                              query;
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange             queryBuildRange;
    ;
    sysTableLookup  = SysTableLookup::newParameters(tablenum(EmplTable), _formControl);
    sysTableLookup.addLookupfield(fieldnum(EmplTable, EmplId));
    sysTableLookup.addLookupfield(fieldnum(EmplTable, legacyEmplId));
    // adding the EmplTable method name() int he lookup methos as follows....    sysTableLookup.addLookupMethod(identifierstr(name));
    query                              =  new Query();
    queryBuildDataSource    =  query.addDataSource(tablenum(EmplTable));
  
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

Saturday, July 9, 2011

Import Data into AX from excel file

static void DataImportToAXFromExcel(Args _args)
{
    SysExcelApplication xlsApplication;
    SysExcelWorkBooks   xlsWorkBookCollection;
    SysExcelWorkBook    xlsWorkBook;
    SysExcelWorksheets  xlsWorkSheetCollection;
    SysExcelWorksheet   xlsWorkSheet;
    SysExcelRange       xlsRange;
    SysExcelCells       Cells;
    SysExcelCell        RCell;
    CommaIO             inFile;

    int                 nRow,i;

    DialogField         dialogPath;
    Dialog              dialog;
    Filename            filename;

    CustTable           custTable;
    CustAccount         custAccount;
    CustGroupId         custGroupId;
    CurrencyCode        currencyCode;
    ;

    dialog = new Dialog("Import");
    dialogPath = dialog.addField(typeid(Filenameopen), "File Name");
    dialog.run();

    if (dialog.run())
    {
        filename = (dialogPath.value());
    }

    inFile = new CommaIO (filename, 'R');

    if (!inFile || infile.status() != IO_Status::Ok )
    {
        throw error (strfmt("@SYS19312",filename));
    }

    try
    {
        xlsApplication          = SysExcelApplication::construct();
        xlsWorkBookCollection   = xlsApplication.workbooks();
        xlsWorkBookCollection.open(filename);
        xlsWorkSheetCollection  = xlsApplication.worksheets();
        xlsWorkSheet            = xlsWorkSheetCollection.itemFromNum(1);
        Cells                   = xlsWorkSheet.Cells();

        nRow = 2;
        RCell = Cells.Item(nRow, 1);

        while(RCell.value().bStr() != "")
        {
            custAccount     = RCell.value().bStr();
            RCell           = Cells.item(nRow,2);
            custGroupId     = RCell.value().bStr();
            RCell           = Cells.item(nRow,3);
            currencyCode    = RCell.value().bStr();

            if(!CustTable::exist(custAccount))
            {
                if(CustGroup::exist(custGroupId) && Currency::exist(currencyCode))
                {
                    custTable.initValue();
                    custTable.AccountNum    = custAccount;
                    custTable.CustGroup     = custGroupId;
                    custTable.Currency      = currencyCode;
                    custTable.insert();
                }
            }
            nRow++;
            RCell = Cells.Item(nRow, 1);
        }
        xlsApplication.quit ();
        xlsApplication.finalize ();
        info("Imported completed");
    }
    catch( Exception::Error)
    {
        //Close Excel.
        xlsApplication.quit ();
        xlsApplication.finalize ();
        ttsabort;
        info("Unable to process the excel import ");
    }
}

Data-upload into AX from CSV file(comma delimited)

Exportfile for AOT version 1.0 or later
Formatversion: 1
***Element: CLS
; Microsoft Dynamics AX Class: ImportDataCSV unloaded
; --------------------------------------------------------------------------------
  CLSVERSION 1
 
  CLASS #ImportDataCSV
    PROPERTIES
      Name                #ImportDataCSV
      Extends             #RunBase
      RunOn               #Called from
    ENDPROPERTIES
   
    METHODS
      Version: 3
      SOURCE #classDeclaration
        #class ImportDataCSV extends RunBase
        #{
        #    FilenameOpen    filename;
        #
        #    CustAccount     custAccount;
        #    CustGroupId     custGroup;
        #    CurrencyCode    currencyCode;
        #
        #    DialogField     dialogFileName;
        #    #define.CurrentVersion(1)
        #    #localmacro.CurrentList
        #            filename
        #    #endmacro
        #}
      ENDSOURCE
      SOURCE #dialog
        #/// <summary>
        #/// The dialog method defines the dialog. The dialog contains a file name.
        #/// </summary>
        #/// <returns>
        #/// The method dialog returns the defined dialog.
        #/// </returns>
        #public Object dialog(DialogRunbase _dialog, boolean _forceOnClient)
        #{
        #    DialogRunbase dialog;
        #    ;
        #
        #    dialog = super(_dialog, _forceOnClient);
        #    dialog.addGroup("Choose File to Upload");
        #    dialogFilename  = dialog.addFieldValue(typeid(FilenameOpen), filename);
        #
        #    return dialog;
        #}
      ENDSOURCE
      SOURCE #getFromDialog
        #public boolean getFromDialog()
        #{
        #    boolean ret;
        #
        #    ret = super();
        #
        #    filename    = dialogFilename.value();
        #
        #    if (!WinApi::fileExists(filename))
        #        ret = checkFailed(strfmt("@SYS18678", filename));
        #
        #    return ret;
        #}
        #
      ENDSOURCE
      SOURCE #pack
        #public container pack()
        #{
        #    return [#CurrentVersion, #CurrentList];
        #}
        #
      ENDSOURCE
      SOURCE #parmFilename
        #public FilenameOpen parmFilename(FilenameOpen _filename = filename)
        #{
        #    ;
        #    filename = _Filename;
        #
        #    return filename;
        #}
        #
      ENDSOURCE
      SOURCE #run
        #public void run()
        #{
        #    AsciiIO             file;
        #    Container           conData;
        #    boolean             first = false;
        #    CustTable           custTable;
        #    ;
        #
        #    file    = new AsciiIO(filename,"R");
        #    if(!file && file.status() != IO_Status::Ok)
        #    {
        #        throw error(strfmt("@SYS19312",filename));
        #    }
        #
        #    file.outRecordDelimiter('\n');
        #    file.inFieldDelimiter(',');
        #
        #    while (file.status() == IO_status::Ok)
        #    {
        #        conData = file.read();
        #
        #        if(first)
        #        {
        #            if(conData != connull())
        #            {
        #                custAccount     = conpeek(conData,1);
        #                custGroup       = conpeek(conData,2);
        #                currencyCode    = conpeek(conData,3);
        #
        #                if(!CustTable::exist(custAccount))
        #                {
        #                    CustTable.initValue();
        #                    CustTable.AccountNum    = custAccount;
        #                    if(CustGroup::exist(custGroup))
        #                    {
        #                        CustTable.CustGroup = custGroup;
        #                    }
        #                    if(Currency::exist(currencyCode))
        #                    {
        #                        CustTable.Currency  = currencyCode;
        #                    }
        #                    CustTable.insert();
        #                }
        #            }
        #        }
        #        first           = true;
        #    }
        #}
        #
      ENDSOURCE
      SOURCE #unpack
        #public boolean unpack(container _packedClass)
        #{
        #    Version version = runbase::getVersion(_packedClass);
        #
        #    switch (version)
        #    {
        #        case #CurrentVersion:
        #            [version, #CurrentList] = _packedClass;
        #            break;
        #
        #        default:
        #            return false;
        #    }
        #
        #    return true;
        #}
        #
      ENDSOURCE
      SOURCE #description
        #client server static ClassDescription description()
        #{
        #    return "Import Customer Data";
        #}
        #
      ENDSOURCE
      SOURCE #main
        #static void main(Args _args)
        #{
        #    ImportDataCSV import = new ImportDataCSV();
        #    ;
        #
        #        if (import.prompt())
        #            import.run();
        #}
        #
      ENDSOURCE
    ENDMETHODS
  ENDCLASS
***Element: END