Monday, October 29, 2012

Sequence of methods in the FORM level in AX


Hi...

This gives the information of method calls in the form level while
1. Opening the Form.
2. Creating/Updating/Deleting the record in the Form.
3. Closing the Form.
Sequence of Methods calls while opening the Form
Form --- init ()
Form --- Datasource --- init ()
Form --- run ()
Form --- Datasource --- execute Query ()
Form --- Datasource --- active ()

Sequence of Methods calls while closing the Form
Form --- canClose ()
Form --- close ()

Sequence of Methods calls while creating the record in the Form
Form --- Datasource --- create ()
Form --- Datasource --- initValue ()
Table --- initValue ()
Form --- Datasource --- active ()

Sequence of Method calls while saving the record in the Form
Form --- Datasource --- ValidateWrite ()
Table --- ValidateWrite ()
Form --- Datasource --- write ()
Table --- insert ()

Sequence of Method calls while deleting the record in the Form
Form --- Datasource --- validatedelete ()
Table --- validatedelete ()
Table --- delete ()
Form --- Datasource --- active ()

Sequence of Methods calls while modifying the fields in the Form
Table --- validateField ()
Table --- modifiedField ()

How to Create a new “Parameters form” for New Module developed in AX


How to develop a new “Parameters form” in case of New Module developed in AX.
We go through it by considering an example of creating the new module as Payroll.
So now we will create the Payroll Parameters setup form for the payroll module.
Initially create a Parameters table for the Module, the naming convention should be the Module name followed by Parameter as in this case it is PayrollParameters table….and need to have the fields accordingly what is required in the Parameters table.
Set the following properties for the parameter table as…

Create a parameter form by considering the PayrollParameters andNumberSequenceReference as data sources. And set the following properties for the data source in the form level as

First thing is that there shouldn’t be any provision to create the record in the parameters form. The record in the Parameters should be by default and it can be updated as per the functionality required
So when creating the new company in the Axapta, the parameters form should have the default values.
To have the default values in the parameters we need to have the following code in the table  level of find() of PayrollParameters tables .
static PayrollParameters find(boolean _forupdate = false)
{
    PayrollParameters  parameter;

    if (_forupdate)
    parameter.selectForUpdate(_forupdate);

    select firstonly parameter
        index Key
        where parameter.Key == 0;

    if (!parameter && !parameter.isTmp())
    {
        Company::createParameter(parameter);
        NumberSeqReference::construct(PayrollParameters::numberSeqModule()).load();
    }

    return parameter;
}

Friday, October 26, 2012

Displaying a Message Box



You can display a message in a modal dialog box by using the Box class.

Some methods in the Box class display a dialog box that contains multiple buttons. These methods have a parameter for choosing which button has focus when the dialog box is first displayed. This parameter is of type DialogButtonenum. Most of these multiple-button methods return a value of type DialogButton enum. This returned value enables your program to branch based on which button the user clicked.
NoteNote
The Box application class calls the DialogBox system class. Don't call it directly—always call the Box class instead.

The following are guidelines to help you create an effective message box:
  • Choose a Box method that matches your purpose.
  • Write the information text to match the buttons in the box.
  • Choose the button best suited for having initial focus.
  • Use the returned DialogButton value to direct the branching in your code.

The following table describes the Box class methods and their associated DialogBoxType system enum values.
Box class static method nameAssociatedDialogBoxTypeenum valueDescription
info
InfoBox
The OK button is the only one that the info method displays in the dialog box.
Use this method to display general information messages rather than for warning or error messages.
infoOnce
InfoBox
The infoOnce method is similar to the info method but with the following differences:
  • Your code cannot set the text in the title bar.
  • An additional header section is displayed under the title bar, and you can set the text that displays in the header.
  • More info button is present. When clicked, it opens a Web browser to the URL string that you supply through a parameter.
The infoOnce method returns void, even though it has two buttons.
infoOnceEx
InfoBox
The infoOnceEx method is similar to the infoOnce method but with the following differences:
  • The infoOnceEx method has a parameter that can be passed in to set the text in the title bar.
  • The infoOnceEx method has a Boolean parameter for choosing whether to have the caller thread continue processing while the user reads the message in the dialog box.
okCancel
OkCancelBox
The OK and Cancel buttons are displayed in the dialog box. Call this method when the user must confirm or reject an action.
stop
StopBox
The OK button is the only one displayed in the dialog box.
Use this method to display a message when the user should stop attempting their action or when a process has stopped running.
warning
WarnBox
The OK button is the only one displayed in the dialog box. Use this dialog box for a warning message.
yesAllNoAllCancel
YesToAllNoToAllBox
The buttons displayed in this dialog box are YesYes to allNoNo to all, and Cancel.
yesNo
YesNoBox
The buttons displayed in this dialog box are Yes and No. Call this method when you need the user to make a choice.
yesNoNoAllCancel
NoToAllBox
The buttons displayed in this dialog box are YesNoNo to all, andCancel.
yesNoAxaptaForm
YesNoBox
The yesNoAxaptaForm method is similar to the yesNo method but with the following differences:
  • The yesNoAxaptaForm dialog box has a different image.
  • The yesNoAxaptaForm dialog box is wider.
yesNoCancel
YesNoCancelBox
The buttons displayed in this dialog box are YesNo, and Cancel. Call this method when the yesNo method is insufficient.
yesNoOnce
YesNoBox
The yesNoOnce method is similar to the yesNo method but with the following differences:
  • The yesNoOnce dialog box has a different image.
  • The yesNoOnce dialog box has a check box that the user can select to suppress any further occurrence of an associated message.
yesYesAllNoCancel
YesToAllBox
The YesYes to allNo, and Cancel buttons are displayed.

The following example displays a message box that contains buttons labeled YesNo, and Cancel. The No button has initial focus. When a button is clicked, a message is displayed in the Print Window to indicate which button was clicked. Run this example as a job in the Application Object Tree (AOT).
static void JobBoxDemo(Args _args)
{
    DialogButton diagBut;
    str strMessage = "The No button should have initial focus.";
    str strTitle = "Title";
    ;
    diagBut = Box::yesNoCancel(
        strMessage,
        DialogButton::No, // Initial focus is on the No button.
        strTitle);
    if (diagBut == DialogButton::No)
        {
            print "The No button was clicked.";
        }
    else
        {
            print "The button that was clicked was: ", diagBut;
        }
    pause;
}
Source : http://msdn.microsoft.com/en-us/library/aa860308(v=ax.50).aspx

Friday, October 19, 2012

Create Bat file to execute commands in AX

Hi,

I wanted to execute the close ax application on certain conditions, so that i have used the .bat file to execute the same.

1) How to create bat file?

  1. Open notepad and enter the command that you have to execute.
  2. As I have to execute the close command for ax i used the following line of code.
         @echo off
          taskkill /F /im Ax32.exe


     3. "Save As" the notepad file with selection of "Save As Type:" : "All files" and enter file name with .bat extension.

2) How to call bat file from ax application ?
    I have executed the "Close application code" on the button click.
 
        void btnCloseAppl()
   {
       str path;
       ;
       path="C:\TestFileToCloseAppl\Axclose.bat";  
       //Kindly check the path may be have to add '\' in between the path  
       winapi::shellExecute(path);
   }

Thanks,
Kishor

Friday, October 12, 2012

User Login and password Form design in AX 2009


If you need to store passwords in AX there are some application objects, classes and attributes that you can use.  This post details the steps you can take to allow entry of a password in a form, which will be stored in the database.

Password form

1.  Add the password field to your table. This field should be of type ‘CryptoBlob’ which is a container that contains binary data:

Password table field

2. Add an edit method for the password to your table:

01 //BP Deviation Documented
02 edit Password editPassword(boolean _set = false, Password _pwd = '')
03 {
04     CryptoBlob cryptoBlob = connull();
05     ;
06   
07     if (_set)
08     {
09         this.Password = WinapiServer::cryptProtectData(str2cryptoblob(_pwd));
10     }
11   
12     return (this.Password == connull()) ? '' : 'xxxxxxxx';
13 }

3. Drag and drop the edit method to your form and ensure that the attribute ‘PasswordStyle’ is set to ‘Yes’:
Password form control
4. To retrieve the password you will need a method similar to the following:

1 static Password getPassword(UserId _userId)
2 {
3     CryptoBlob cryptoBlob = TutorialPasswordTable::find(_userId).Password;
4     ;
5   
6     return (cryptoBlob == connull()) ? '' :
7                 cryptoblob2str(WinapiServer::cryptUnProtectData(cryptoBlob));
8 }


Disclaimer
The safest way to handle passwords is not to store them in the database. The steps described in this post are better than storing the password in the database as plain text, but far from bulletproof. Please ensure that AX security is fully considered if using this method (Table level security, access to code / development etc)
You can download the tutorial as an xpo here from axaptapedia

Restrict multiple times user login in AX 2009


Hie,

Currently in Ax 2009 the user can login  multiple times in application, so to restrict users to open Ax 2009  multiple times we can use the following code.

** Before implementing this please take backup of your application files
Open Classes --> info --> StartupPost metod 
and copy following code into this method

void startupPost()
{
// To restrict user login form second login
xSession                    session;
SysClientSessions    SysClientSessions;
UserId                      currentUserId;
int                             counter;
;
currentUserId = curUserId();
if(currentUserId!=”Admin”)                     // Allow Admin User to login multiple time
{
    while select SysClientSessions
    where SysClientSessions.userId == currentUserId  
    && SysClientSessions.Status == 1   // 1 : Login 0 : Logout
    {
        session = new xSession(SysClientSessions.SessionId, true);

        if (session && session.userId())
        {
              counter++;
        }
    }
    if(counter>=2)
    {
         Box::stop(“Already Logged-in : The same user id can’t log in twice.”);
         infolog.shutDown(true);
     }
}
}