Wednesday 11 December 2013

Number Sequence in Dynamics Ax

Microsoft Dynamics AX has a number sequence framework to generate alphanumeric number sequences that are used to identify transaction documents such as sales orders, purchase order and others.

We can create number sequence with existing module or new module. For both condition, first we create a table “BookTable” with two fields “BookId” and “Name” and create index on table called “BookIdx” and drag-drop “BookId” field on it. 

Figure 1. Create BookTable

Create a form “BookForm” and drag-drop “BookTable” in the datasource and create design according figure 2.

Figure 2. Create BookForm

Now, we create number sequence with existing module or new module.

 1. Create number sequence with existing module

1.Create a EDT that extends num and Add a relation in EDT.

Figure 3. Create EDT 


2.Edit a class NumberseqReference_CustTable  and  modify “loadModule()” method

   numRef.dataTypeId = typeId2ExtendedTypeId(typeid(Book_edt));        
    numRef.referenceHelp="Unique key for the Complaint Report";
    numRef.wizardContinuous = true;  
    numRef.wizardManual = NoYes::No;            
    numRef.wizardAllowChangeDown = NoYes::No;              
    numRef.wizardAllowChangeUp= NoYes::No;          
    numRef.wizardHighest= 999999;    
    numRef.sortField = 19;       
    this.create(numRef);

3.Modify CustParameters Table and Add methods.

   static client server NumberSequenceReference numRefComplaintId()
    {
     return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(Book_edt)));
   }

4.In the “BookForm” classDeclaration declare NumberSeqFormHandler.

5.On “BookForm”  under “BookTable” datasource – Override write(), Delete(), create() methods like:

public void write()
{   super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();
}
public void delete()
{   element.numberSeqFormHandler().formMethodDataSourceDelete();
    super();
}
public void create(boolean _append = false)
{   element.numberSeqFormHandler().formMethodDataSourceCreatePre();
    super(_append);
    element.numberSeqFormHandler().formMethodDataSourceCreate();
}

6.create method on “BookForm” form methods.

NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
        {
            numberSeqFormHandler = NumberSeqFormHandler::newForm(CustParameters::numRefComplaintId().NumberSequence, element, BookTable.dataSource(), fieldnum(BookTable, BookId));
        }
    return numberSeqFormHandler;
}

7. Goto>Basic>Setup>Number sequences>create new Number sequence code and set fields according to you
8. Goto> References>find new number sequence reference and set number sequence code field.


2. Create number sequence with new  module

1.Create a EDT that extends num and Add a relation in EDT
2.Modify numseqmodule Enum and a element “Book”.
3.Create  a class NumberseqReference_Book  that extend NumberSeqReference class and  Add loadModule() method and numberSeqModule().

protected void loadModule()
{
    NumberSequenceReference numRef;
    ;
    /* Setup Book Details */
    numRef.DataTypeId = typeId2ExtendedTypeId(typeid(Book_edt));
    numRef.ConfigurationKeyId = configurationkeynum(Test);
    numRef.ReferenceHelp ="Unique key for test identification. ";
    numRef.WizardManual = NoYes::No;
    numRef.WizardAllowChangeDown = NoYes::No;
    numRef.WizardAllowChangeUp = NoYes::No;
    numRef.SortField = 1;
    this.create(numRef);
}
public static client server NumberSeqModule numberSeqModule()
{
    ;
    return NumberSeqModule::Book;
}

4.Create  “BookParameters” Table and Add methods

client server static NumberSequenceReference numRefBookId()
{
    return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(Book_edt)));
}
Figure 4. Create BookParameters Table

5.In the “BookForm” classDeclaration declare NumberSeqFormHandler.

6.On “BookForm”  under “BookTable” datasource – Override write(), Delete(), create() methods like:

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

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

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

7.create method on “BookForm” form methods.

NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
        {
            numberSeqFormHandler = NumberSeqFormHandler::newForm(BookParameters::numRefBookId().NumberSequence, element, BookTable.dataSource(), fieldnum(BookTable, BookId));
        }
    return numberSeqFormHandler;
}

8. Goto>Basic>Setup>Number sequences>create new Number sequence code and set fields according to you
9. Goto> References>find new number sequence reference and set number sequence code field.


3. In Dynamics Ax 2012 it is require that Create a new job with the following code and run it to call all loadModule:

           static void NumberSeqLoadAll(Args _args)
            {
                   NumberSeqApplicationModule::loadAll();
            }


Friday 6 December 2013

How to create Authentication form when the Dynamics Ax open.

In this section I’ll show you how to create authentication form when the dynamics ax open. This form will contain username and password stringEdit control fields. Both fields verify username and password for security. If you’ll enter wrong username and password dynamics ax environment will not open and if you close authentication form dynamics ax environment will automatically shutdown. I’m showing you implementing this functionality step by step-:

Step 1 – Create a form named “AuthenticationForm” with following designs.

Figure 1. Create AuthenticationForm.

Step 2 – Set below properties on form controls and buttons-
      1. Design
                 Width – 10
                 Height – 70
                 Caption – Authentication
      2. StringEdit:UserName
                AutoDeclaration  – Yes
                Label – Username
      3. StringEdit:Password
                AutoDeclaration  – Yes
                PasswordStyle - Yes
                Label – Password
      4. Button:Login
                Text – Log In
      5. Button:Cancel
               Text – Cancel

Step 3 – Override methods on buttons and form-
1. Override “close()” method on form methods and write code-
            public void close()
             {
                     infoLog.shutDown(true);
                     super();
              }

2. Override “clicked()” method on “Button:Login” and write below code-
        void clicked()
           {
                    str un, pass;
                    ;
                   un = UserName.text();
                   pass = Password.text();
                   if(un == "kamal" && pass == "jangir")
                    {
                             box::info("User name and Password correct");
                            element.closeOk();
                    }
                  else
                    {
                             box::info("User name and Password incorrect Try again");
                    }
                  super();
          }

3. Override “clicked()” method on “Button:Cancel” and write below code-
         void clicked()
         {
                 ;
                 box::info("Ax Closed");
                infoLog.shutDown(true);
               super();
        }

Step 3 – Now Go to Classes and find info class and create a new method-

static void openFormByCode2(Args _args)
{
    FormRun formRun;
    Args args = new Args();
    ;
    args.name(formstr(AuthenticationForm));
   
    formRun = ClassFactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.wait();
}

Step 4 – Finally override “startup()” method on info class(Classes/Info/startup() ) and add below code-
        Args _args;
    ;
    _args = new Args();
    info::openFormByCode2(_args);


Now open new dynamics ax environment and check but be careful don’t close current environment.