n 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-
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.
No comments:
Post a Comment