Monday, September 2, 2013

Simple UI Builder Class in SSRS Report in AX 2012

This UI Builder class is simple class with less code and less effort. UI Builder Class is needed when you want to customize your dialog which pop ups when you open a Report. UI Builder Class helps you to add run time lookups and other controls on the dialog form.
Step1 : Your Class must extends SrsReportDataContractUIBuilder
class SimpleDemoUIBuilder extends SrsReportDataContractUIBuilder
{
DialogField dialogEmplId;
DialogField dialogName;
boolean enable;
SimpleDemoContract contract;
}// two fields emplId and Name will reflect in the lookup in dialog form at the time of report opening.
Step2 : Override the build method
public void build()
{
contract = this.dataContractObject();
dialogEmplId = this.addDialogField(methodStr(SimpleDemoContract, parmEmplId),contract);
}// this method used for adding the field  which is from contract class.
Step3 : Write this below code to get lookup
private void emplIdLookup(FormStringControl emplIdlookup)
{
Query query = new Query();
QueryBuildDataSource qbds_EmplTable;
SysTableLookup sysTableLookup;
// Create an instance of SysTableLookup with the current calling form control.
sysTableLookup = SysTableLookup::newParameters(tableNum(FilterDemo), emplIdlookup);
// Add fields to be shown in the lookup form.
sysTableLookup.addLookupfield(fieldNum(FilterDemo,EmplId));
sysTableLookup.addLookupfield(fieldNum(FilterDemo,Name));
qbds_EmplTable = query.addDataSource(tableNum(FilterDemo));
sysTableLookup.parmQuery(query);
// Perform the lookup
sysTableLookup.performFormLookup();
}
Step4 : Override this method
public void getFromDialog()
{
contract = this.dataContractObject();
super();
}
Step5 : Override this method
public void initializeFields()
{
contract = this.dataContractObject();
}
Step6 : Override this method
public void postBuild()
{
super();
dialogEmplId = this.bindInfo().getDialogField(this.dataContractObject(),methodStr(SimpleDemoContract,parmEmplId));dialogEmplId.registerOverrideMethod(methodStr(FormStringControl, lookup),
methodStr(SimpleDemoUIBuilder,emplIdLookup), this);dialogEmplId.lookupButton(2);
}
the Contract Class code and DP class have already been added to the blog. please check it for further reference but one important part has to be added to the contract class i.e in class declaration, the following part has to be updated.

[DataContractAttribute,SysOperationContractProcessingAttribute(classstr(SimpleDemoUIBuilder))]

Working with SSRS reports in Dynamics AX 2012

Microsoft Dynamics AX provides a model-based approach for creating reports by providing project templates and modeling tools that are incorporated into the Microsoft Visual Studio development environment. The reporting features provided by Microsoft Dynamics AX are tightly integrated with SQL Server Reporting Services.
Reporting Services is a server-based reporting platform that provides comprehensive reporting functionality for a variety of data sources. The reporting framework includes a set of tools for you to define reports in the Microsoft Visual Studio development environment. The report development experience takes advantage of extended SQL Server tools and components fully integrated into the Microsoft Visual Studio environment. By using the reporting APIs, you can integrate or extend data and report processing in custom applications. The following table provides links to more information on these Microsoft technologies:
You can refere following url for more information about report development with SSRS,Dynamics AX 2012. 

Setting SysEntryPointAttribute for Services [AX 2012]

The SysEntryPointAttribute indicates what authorization checks are performed for a method that is called on the server. This attribute must be set for all service operations. For more information about how to set attributes on X++ methods, see Syntax for Attribute Classes.
The AIF Document Service Wizard automatically decorates service operations with [SysEntryPointAttribute(true)]. When you develop custom services you must use theSysEntryPointAttribute to decorate each service operation.
Setting :
The following table describes the possible values for the constructor of the SysEntryPointAttribute class.
[SysEntryPointAttribute(true)] - Indicates authorization checks are performed on the calling user for all tables accessed by the method.

[SysEntryPointAttribute(false)] - Indicates authorization checks are not performed on any tables accessed by the method.

Example :
[AifDocumentCreateAttribute, SysEntryPointAttribute(true)]
public AifEntityKeyList create(CustCustomer _custCustomer)
{
    return this.createList(_custCustomer);
}

reference : http://technet.microsoft.com/en-us/library/hh801193.aspx

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.