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.

Monday, August 6, 2012

Error: Cannot create a record in . The record already exists

Thanks to Amer Atiyah.....:)
Source : Amer Atiyah's Blog


Sometimes you might face an unexpected error when trying to insert new records to any of the Dynamics AX tables. The message you might have is like: Cannot create a record in Journal lines (LedgerJournalTrans). The record already exists.
You might also have tried to check the indexes of this table that shouldn’t be duplicated. And you got surprised when you are not violating those constraints, so there is no any rational reason why this error might appear.
After so many tries, I got to fix that error by:
  1. Backing-up my database (just in case that anything went wrong)
  2. Exporting the data of that table (from the AX Import/Export functionality)
  3. Deleting/Dropping the table from the Microsoft SQL Server Management Studio (by this all the data of course will be deleted)
  4. Opening the Dynamics AX client, going to: AOT –> Data Dictionary –> Tables –> LedgerJournalTrans –> Right clieck –> Synchronize
  5. Importing the data again to all companies (from the AX Import/Export functionality.
As you could see, I got this error in a very critical table that is the LedgerJournalTrans table. This table contained already posted lines and it was really headache for me to get it fixed. But fortunately I was able to fix it by following the previous steps. :)