Thursday, August 22, 2013

WINAPI functions and their use

Like most AX developers I use the WINAPI class quite often. Its a very useful class when handling files that need to be accessed outside of the AX environment

  static void FO_WinApi(Args _args)
  {
      str     root        = "C:";
      str     path        = "C:\\dionne";
      str     fileName    = "SalesInvoice.pdf";
      str     fileName2   = "SalesInvoice1.pdf";
      str     file        = path + "\\" + fileName;
      str     file2       = path + "\\" + fileName2;
      int     x, y;
      ;

      // Does folder exist?
      print WinAPI::folderExists(path);

      // Does file exist?
      print WinAPI::fileExists(file);

      // Copy file.
      print WinAPI::copyFile(file,file2);

      // New file exists?
      print WinAPI::fileExists(file2);

      // Delete new file.
      print WinAPI::deleteFile(file2);

      // New file still there?
      print WinAPI::fileExists(file2);

      // Get current cursor position.
      [x, y] = WinAPI::getCursorPos();

      print x;
      print y;

      // Get time and date format.
      print WinAPI::getSystemLocaleDateStr();
      print WinAPI::getSystemLocaleTimeStr();

      // Gets current computer name.
      print WinAPI::getComputerName();

      // Gets total disk space.
      print int2str(WinAPI::getDiskTotalSpaceInKb(root)
             / 1000) + " MB";

      // Gets current free space on disk.
      print int2str(WinAPI::getDiskFreeSpaceInKb(root)
             / 1000) + " MB";

      // Date when file was last accessed.
      print WinAPI::getFileAccessedDate(file);

      // Time when file was last accessed(In seconds).
      print WinAPI::getFileAccessedTime(file);

      // Gets path to temp directory.
      print WinAPI::getTempPath();

      // Gets a generated temporary filename, prefix "FO_".
      print WinAPI::getTempFilename(path, "FO_");

      pause;

  }
In addition to file information the WINAPI class can execute different file types from within Dynamics AX by of course using the file name as a parameter.
For example lets say you want to launch a PDF file saved in table within AX. WinAPI::ShellExecute() will do this for you.
- See more at: http://www.winfosoft.com/blog/microsoft-dynamics-ax/the-winapi-class#sthash.3QzP3keO.dpuf


reference from :http://www.winfosoft.com/blog/microsoft-dynamics-ax/the-winapi-class

Wednesday, August 14, 2013

Monday, August 12, 2013

AX 2012 : How to create new number sequence ?

Number sequences in Dynamics AX are used to generate specifically formatted numbers for record identification. for example Sales Id, Purchase Id, Journal number etc.
Very often we need to customize functionality which require new number sequence to be generated for new table designed.Dynamics AX contains a list of NumberSeqApplicationModule derivative classes, which holds the number sequence setup data for the specific module. These classes are read by the number sequence wizard, which detects existing number sequences and proposes to create the missing ones or newly added ones.
Suppose we have created new table “KitTable” with fields KitId and KitName, and we have to generate number sequence for KitId. This table belongs to Sales module.
Lets look at the steps to do this job :
1. Open the NumberSeqModuleCustomer class in the Application Object Tree (AOT), and add the following code to the bottom of the loadModule() method:
datatype.parmDatatypeId(extendedTypeNum(KitId));
datatype.parmReferenceHelp(“Kit ID”);
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChangeDownAllowed(NoYes::Yes);
datatype.parmWizardIsChangeUpAllowed(NoYes::Yes);
datatype.parmWizardHighest(999);
datatype.parmSortField(20);
datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype);
2. Create a new job with the following code and run it:
static void NumberSeqLoadAll(Args _args)
{
NumberSeqApplicationModule::loadAll();
}
3. Run the number sequence wizard by clicking on the Generate button inOrganization administration | Common | Number sequences | Number sequences, and click on the Next button, as shown in the following screenshot:
4. Click on Details to view more information. Delete everything apart from the lines where Area is Accounts receivable and Reference is Kit Id. Note the number sequence codes, and click on the Next button.
5. On the last page, click on the Finish button to complete the set up.
6. The newly created number sequences can now be found in Organization administration | Number sequences | Number sequences
7. Open Organization administration | Number sequences | Segment configurationand notice the new Kit Id reference.
8. Open Accounts receivable | Setup | Accounts receivable parameters and go to the Number sequences tab page. Here we should see the new number sequence code.
9. The last thing to do is to create a helper method for this number sequence. Locate theCustParameters table in the AOT and create the following method:
public server static NumberSequenceReference numRefKitId()
{
return NumberSeqReference::findReference(extendedTypeNum(KitId));
}
Now lets see how the above code works :
We added a number sequence initialization code into the NumberSeqModuleCustomerclass. This class holds the initialization of all number sequences that belong to the Accounts receivable module. The code in the loadModule() method defines the default number sequence settings to be used in the wizard, such as data type, description, highest possible number, and so on.
Additional options, such as starting sequence number, number format, and others could also be added here. All mentioned options could be changed while running the wizard. The addParameterType() method is used to define number sequence scope. In the example we created a separate sequence for each Dynamics AX company.
Before we start the wizard, we need to initialize number sequence references. This is normally done as a part of the Dynamics AX initialization checklist, but in this example we have to execute it manually by calling the loadAll() method of theNumberSeqApplicationModule class.
Next, we will run the wizard. We will skip the welcome page and in the second step of the wizard, the Details button can be used to display more options. The options can also be changed later in the Number sequences form before or even after the number sequence is actually used. The last page shows an overview of what will be created. Once completed, the wizard creates new records in the Number sequences form for each company.
The newly created number sequence reference appears in the Segment configurationform. Here we can see that the Data area checkbox is checked, meaning that we will have separate number lists for each company. The number sequence setup can normally be located in the module parameter forms.

Friday, July 19, 2013

How can I see the SQL query that the Dynamics AX Kernel is generating for my Form?

When you are debugging your solution you sometimes might want to see the SQL Query the Dynamics AX Kernel has generated for your Form. 
While you can of course trace this directly at your Database Server, you also can do this in X++ using the QueryBuildDataSource class.

Let's imagine you have a Form that has PurchTable as Data Source. You have to override the executeQuery method of the PurchTable Data Source and add the following code:

public void executeQuery()
{
   Query q;
   QueryBuildDataSource qbds;
   ;
   q = this.query();
   qbds = q.dataSourceName("PurchTable"); //Replace with the                                                 current Table
   info( qbds.toString() );

   super();
}

Thursday, July 11, 2013

Friday, May 3, 2013

Management Reporter 2012 server installation and configuration


Run the downloaded ManagementReporter2012-en-us.exe and select a location for the installation files to be extracted to;
Choose directory for extracted files
Once extraction is complete, hit OK;
Extraction Complete
In the extract location you’ll see a collection of files and a pkg folder. Double click the Setup.exe to start the installation process and select Install Management Reporter Server;
Management Reporter Setup
Accept the terms of the License Agreement after reading it;
Management Reporter Setup - Microsoft Software License Terms
Select or confirm the destination folder;
Management Reporter Setup - Specify Destination Folder
Click Install to confirm the installation;
Management Reporter Setup - Ready to Install Management Reporter
Management Reporter will then install before confirming a successful installation;
At this stage you can choose to start the Configuration Console of Management Reporter when you click finish. You can also proceed further without selection of check box and configure it afterwards.
Configuring Management Reporter 2012:

The configuration is done using the Configuration Console which is installed as part of the server installation, so in my case it is on the Reporting Server (RPT1).
To start the Configuration Console go to Start >> All Programs >> Microsoft Dynamics >> Management Reporter 2012 >> Configuration Console. Once started it will detect that configuration has not yet been done and present you with the Custom Configuration wizard;
Configure Management Reporter - Custom Configuration
By default both Microsoft Reporter Application Service and Management Reporter Process Service will be checked, and as I am dealing with Management Reporter integrated with Dynamics GP I also need to select Add Microsoft Dynamics GP;
Configure Management Reporter - Custom Configuration
If any prerequisites are missing, such as the Access Database Engine, you will be shown them and given the opportunity to install them before proceeding;
Configure Management Reporter - Prerequisite Validation
Next you need to configure the Service account. For a production environment this should always be a custom account with restricted privileges and a password that never expires (if you type in the username, ensure the Domain element is in all caps; e.g. DOMAIN\DynamicsGPuser) and supply the password;
Configure Management Reporter - Settings
Next, the database configuration needs to be completed. Enter the name of the SQL Server that the Management Reporter database will live on (in my case RPT1) and select the authentication method, either accept the default ManagementReporter database name or supply your own, enter a master key for encrypting sensitive information and select your Management Reporter administrator user (this will default to the logged in user);
Configure Management Reporter - Settings
Configure the port which should be used for the Application Service (4712 is the default (this is the same port as Management Reporter 2).
You also need to define the Dynamics GP connection information (the eagle eyed among you will spot the Database server has been spcified as GPLIVE and not SQL1; this is because I have created a CNAME alias for the GP Server so I can move the installation in future to a new server without having to reset all passwords) and select the system Database;
Configure Management Reporter - Settings
Check the configuration summary and then click Configure to proceed;
Configure Management Reporter - Ready to Configure
Once configure is complete this will be confirmed or any errors reported;
Configure Management Reporter - Ready to Configure
Once you click close you’ll be returned to the Management Reporter Configuration Console where you can see the status of Management Reporter;
Management Reporter 2012 Configuration Console
To add companies from Microsoft Dynamics GP, select Management Reporter Services >> ERP Integrations >> SERVER (DYNAMICS) in the Navigation Pane and click the Import button on the Server (DYNAMICS) detail pane;
Management Reporter 2012 Configuration Console
You will be prompted to enter the GP credentials (in this case I used the sa user);
Enter credentials
You’ll be presented a list of companies which can be imported, and can select companies which have already been imported or those which should be skipped. When you’re ready click the Import Companies button located at the bottom right of the window;
Management Reporter 2012 Configuration Console
Management Reporter 2012 Configuration Console will confirm that the selected companies have been imported;
Management Reporter 2012 - 1 companies were imported successfully
And that is the final part of the Management Reporter 2012 server configuration process. Next up is the client installation process…