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);
     }
}
}

Ax 2009 Login or Startup Message


Hi Friends,
Following are the two methods which are useful to show start-up message at the beginning of AX 2009. 
1.  Update the Client configuration Utility option.
    Microsoft Dynamics AX Configuration Utility (client) -> Genereal Tab -> Field "Startup Message"

2. If you have to add the custom message as per users name at the beginning of AX 2009 then update the  following code in Classes---> Info class---> StartUpPost method.
void startupPost()
{
    UserInfo UserInfo;
    select Name from UserInfo where UserInfo.id==curUserId();
    info('Welcome to '+UserInfo.name);
}

Wednesday, August 29, 2012

Debug Assertion Failed Error

Hi Friends,

While opening the "open transaction editing" from Customer Details Form --> Functions the error raised in debug mode as
Debug assertion failed
The debug window shows the code as Debug::assert( variableName or condition)
For this i debug all the classes and table methods which are included in it and at the end luckily resolve the error.

Solution: 
1) Go to class CustVendOpenTransManager
2) Go to method new()
3) Comment the line this.initMarkedTransBalances(); or you can skip this line while debug this class. ( i prefer for skipping the line of code while debugging the class because editing class will leads to import export of that class which will again taking a time.)
4) The next line of code which includes this.initMarkedPayment(); execute this with F11 and further code till you get window mentioned in point 5.

I have attached the screen shot of that class and hi-lighted the line.


5) Skip all the code execution till this window appears to you. Execute the last line of code i.e.  this.refereshMarkedTransactionsBalances();



6) After this just run the remaining code of classes and you will get the following window.


7) Click on Yes and the error is resolved.

Regards,
Kishor Jadhav

Wednesday, August 22, 2012

Form LedgerJournalTransCustPaym requires an active buffer.

This is a standard bug, which should be posted to MBS. 
Form LedgerJournalTransCustPaym can only be started from a "main" form like LedgerJournalTable.  Form LedgerJournalTransCustPaym check if started from main form. If not this error message is posted.