Difference between Refresh(), Reread(), Research() and ExecuteQuery() in AX 2012

In X++ we have the below methods for fetching data after any changes are made, below is the short description of what they are and when to use each one.

Refresh() refreshes the user view with whats stored in the caches. This does not touch the DB.
Use this after any form change has been made through code.

ReRead() fetches only the current record from database and does not re read the complete datasource.
Use this when you need to update only the current record after modifying any value.

ReSearch() will execute the same query again and fetch the results from the database.
Use this if you need to get the current most data from database.

ExecuteQuery() will run the query again just like research does but it will also take any query changes into account.
Use this is you have modified the query on run-time and need the updated results according to the new query.

Advertisements

Solution to Error: Save encoded certificate to store failed => 0x5 (5)

While creating a certificate with the MakeCert utility you might face this Error: Save encoded certificate to store failed => 0x5 (5) as I did, dont be worried its not about your command the solution to this is to simply start your command prompt or powershell as an administrator and then run the command; the certificate will be created successfully.

Creating an ISV License File from MS Dynamics AX 2012 Model using AxUtil

Us ISVs( Independent Software Vendors) want to make our own customized Ax solutions to run on predefined licenses so we can better monetize our solutions, well thanks to Microsoft we now have an ISV licensing feature to do this and do not need to create our own licensing mechanisms. The ISV licensing feature includes the following key capabilities:

  • ISVs can generate their own Boolean licenses.
  • A run-time check that ensures an ISV-generated license key exists.
Dynamics AX ISV licensing

You can read more about ISV licensing here. In this post I will be showing you step by step how you can create your own ISV licence against a model. Before you can create a license you also need to have certificates in order to sign that license so here are the complete steps from start to end:

  1. First and foremost make sure you implement the desired roles and security in your code and tie all objects in your solution to it.
  2. Create a configuration key (or a parent-child configuration key hierarchy) for the solution.
  3. All code elements must bind to a proper configuration key or a hierarchy of configuration keys.
  4. Make sure all code written for this solution has been moved to ISV layer and to a particular model.
  5. Create a license code in the AOT.
  6. Set the Authenticode (x.509 Certificate) to the license file. Go to the license code properties and find the ‘CertificateName’ item and provide ‘cer’ file (the public part of the certificate, You will use the SPC.cer file for this). Keep the private key (.pfx) part secure as it will be used to generate license file. Here are some details on how to do this:
      1. Locate windows SDK on your machine, usually comes with .Net Framework, in my case I found it at following location

      C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin

      1. Copy following files from above folder to a new folder D:\Certificate folder, this would avoid wasting your time trying to run command on C:\ with no rights
        1. MakeCert.exe
        2. pvk2pfx.exe
    • To create a test certificate you can use the makecert utility, this will give you the .cer and .pvk file; as some of you faced problems with certificates I would like to add something here that I previously missed to mention. To use our own certificate we first need to create a CA(Certificate Authority) and then publish  a code signing certificate through that authority. Creating a certificate authority is done through makecert as follows on power shell run the following command to create a CA:
      • .\makecert -r -pe -n “CN=CompanyName O=CompanyName” -ss CA -sr LocalMachine -a sha256 -len 2048 -cy authority -sky signature -sv CA.pvk CA.cer
    • Now to publish a code signing certificate from our created authority; on powershell run the following command:
      • .\makecert -pe -n “CN=CompanyName O=CompanyName” -ss ISVStore -sr LocalMachine -a sha256 -len 2048 -cy end -sky signature -eku 1.3.6.1.5.5.7.3.3 -ic CA.cer -iv CA.pvk -sv SPC.pvk SPC.cer
    • To create the .pfx file you will need to convert the pvk to pfx; run the following command:
      • pvk2pfx.exe -pvk SPC.pvk -spc SPC.cer -pfx FileName.pfx -po password
  7. Assign the license code to the configuration key. In the parent configuration key, select the license code in the properties. This locks everything together if hierarchy is maintained among other configuration keys.
  8. Generate a FULL CIL.
  9. Export the model by going to Start > Administrative Tools > Microsoft Dynamics AX 2012 Management Shell. Enter following command: axutil export /model:[ModelName] /file:[modelfilename] /key:[keyfilename]
    1. [ModelName] is the name of the model
    2. [modelfilename] is the path with filename to export the model to.
    3. [keyfilename] is the strong name key generated using SN.EXE tool, in the case you want to sign the model with a strong named key. You can skip this part if you apply next step, which is to sign the model using a certificate.
  10. Sign the model with certificate
    1. You need a tool ‘SignTool’. You can get by installing Windows SDK.
    2. Run following command:
      • signtool sign /f “[PFX file]” /p [PFX password] “[Path to the model file]”

Once you have implemented the code with the above approach, you can then generate a license for your solution as explained below:

  1. Axutil genlicense /file:licensefile /certificatepath:filepath /licensecode:name /customer:name /serialnumber:number /password:value /expirationdate:date /usercount:count
    1. /file:licensefile specifies the name of the generated license file
    2. /certificatepath:filepath specifies the path to the certificate used to generate the license file. It is the private part of the X.509 certificate used on the licensed Code within AOT; basically the .pfx file.
    3. /licensecode:name specifies the name of the license code used to generate the license file.
    4. /customer:name specifies the customer name used to generate the license file. This will be provided by the Customer, it will be the Customer name on the AX license they have on their installation.
    5. /serialnumber:number specifies the serial number used to generate the license file. This will be provided by the Customer, it will be the serial number of AX license they have on their installation.
    6. /password:value is the value that must match the password of the certificate used to generate the license file.
    7. /expirationdate:date specifies expiration date of the generated license. This parameter is optional.
    8. /usercount:count specifies the number of simultaneous users for the generated license. This parameter is optional. (This is not supported anymore, so you can skip this)
    9. After running this command you can write “type [licensefilename]” to see the content if the license file.
  2. After you have your license you will share the model file and license file with the customer, also if you have created a self signed certificate(as we did with the makecert utility) then your customer needs to trust your Certificate Authority before they import the model and license. To do this simply run the command below on your customers environment:
    • certutil -addstore Root CA.cer
      • This adds it into the Windows certificate store.

Hope this post was helpful, for any questions feel free to leave a comment. Here are some good resources that helped me understand ISV licensing.

UPDATED: To overcome the “Certificate associated with license XXX is not a trusted certificate.” Error while importing license file the complete steps for creating our own certificate have been update, please find the updates in blue text.

Difference between menu item types; Display, Output and Action in Dynamics Ax

Menut item types

 

Developers often ask me what the difference is between the three different menu item types shown in AOT and when should you use them as it appears that all menu items inside the three ‘folders’ I would say have the same set of properties and support the same object types. So what is the difference? The answer is that there is no difference, the difference is a conceptual one rather than a functional or a technical one.

1. Display Menu item

This folder is used to contain menu items that reference runnable objects which are primarily for presenting data to the user such as forms and dialog’s.

2. Output Menu item

An output menu item should have the soul purpose to print a result, mostly used for referencing classes.

3. Action Menu item

As the name says it, you should create a menu item under this folder if your runnable object has an action to perform, for example creating or updating data.

So choosing between these three is on the developers sole discretion and I hope now you’ll be able to make a better choice for your scenario. A basic rule of thumb is:

Display – for Form

Output  – for Report

Action   – for classes.

For more information visit :  Msdn Menu Items Best Practices [AX 2012]

11 Key Reasons Why Businesses Should Use ERP

1. Interaction between departments – flow of information from department to department will no longer be a hassle. Departments that have no interaction with each other but are dependent on data from each other will become efficient.

2. Redundancy protection – Data redundancy is never a problem. Customer, vendor or any similar data that is usually very redundant and hard to keep updated across the company will be taken care of by the ERP system in place by having a single store and multiple access points for its users.

3. Business process automation – complete business processes can be automated regardless of cross department or cross company worries. Using workflows and assignment capabilities available in all leading ERP systems.

4. Detailed Reporting – due to consolidation and presence of all data in a single place, extensive reporting can be performed from the manufacturing to the marketing end. Which enables insights into reasons and predictions of success and failure.

5. Manageability of the system – it is far easy to maintain and manage a single system that is used by the whole organisation than to manage different independent systems.

6. Better auditing – Tighter controls over data enable better and complete auditing.

7. Efficient product development – When the marketing department can access manufacturing data and make decisions over it, efficient and timely product development is easy to achieve.

9. Easier alignment with customer demands – ERP systems like Microsoft Dynamics Ax contain CRM modules that give insight to the organizations customer base and their needs.

10. Forecasting powers – With such detail and accuracy in data across the organization comes the power to forecast budgets and more over forecast positions which has been included in the upcoming release of Dynamics Ax R3. Companies can forecast budgets and it can be done for as many future years as needed.

 11. Tracking and visibility – Workflows with ERP systems provide tracking and visibility to various areas from a Purchase requisition to a purchase order.

These are some key reasons why a business should use ERP, depending on the industry there are several specific reasons to use an ERP system to support the organization in meeting its needs. If you are still questioning whether your company really does need an ERP system like Microsoft Dynamics Ax feel free to contact me onLinkedin or tweet to me and I will try to hook you up with one of our experts at mazikglobal.

Debugging workflow event handlers in Dynamics Ax 2012

To debug X++ code written in event handler classes of a workflow, you need to follow these steps:

1. Run an incremental IL if you have made any changes to the class.

2. Visit Application explorer in visual studio and open the class you want to debug.Applicationexplorer in visual studio

3. In VS goto Debug option and click on Attach to Process and change code type to Manage v4.0

Attached to process for debugging

4. Select show all process in all sessions and select Ax32Serv.exe
(note: you might see more than one Server process, if you cant determine which one to select then select all Ax32Serv process) and attach.

Attach to Ax32serv process

 

final step to attachment

5. Now place breakpoints on the code you want to debug and run the workflow, execution will stop in visual studio once the event is fired.

 

For more information visit : Msdn How to: Debug X++ Code in Workflow [AX 2012]

ProTip: If you would like to see the workflow going into and out of the process que use the form Tutorial_WorkflowProcessor and run it before starting the workflow.Tutorial workflow processor

 

7 Major problems that businesses can overcome by using an ERP solution

Company avoding problems

1. Data Redundancy

By using an ERP system like Microsoft Dynamics Ax you say bye to any redundant or contradictory data. One system maintains all data across the company and eliminates the chances of duplicates.

2. Inventory Inaccuracy

A major problem faced by companies handling inventory on paper or on separate software solutions which are not integrated with manufacturing and sales. ERP systems have proven to provide accurate inventory numbers which in turn help many folds in making sales and marketing a product.

3. Insufficient Reporting

A pain that is rarely addressed in a perfect manner without using an ERP. Insufficient reporting is related to the lack of complete reporting with cross department data and also real time visibility into the status of all processes from quote to cash for decision makers.

4. Manual Paper Processes

Believe it or not companies still handle paper which is a problem in itself. Large to medium corporations that do have electronic systems in place for manufacturing, inventory management and sales still have to use paper to run through processes of finance, human resource management and budgeting. So why use paper and different solutions when the answer to all pains of a company are in ERP solution.

5. Organizational Scalability Issues

When it comes to implementing an ERP decision makers often ask the question as to why they need it if they have functioned well without it.  This is right for companies that do not foresee growth and expect to stay static but growth can have effects on the business that require everything to be scaled up in proportion to growth, this is where an ERP system can support your company well and be a back bone behind the growth rather than being a back pain.

6. Low Customer Retention

ERP has proven to have positive effects on customer retention. Well connected and aware departments are able to react faster to the customers needs and make timely and accurate decisions.

7. Maintaining Separate Systems

If a company is not using an ERP then they will likely be using accounting applications, spreedsheets, desktop applications, home grown applications and disparate applications. All of these systems increase the chances of contradictory data because they are hard to maintain and update and have an overall larger cost for doing so.

 

Lastly, the benefits of using an ERP outrun the effort that is needed to implement and adopt it. Companies that have adopted ERP systems have witnessed reduced operating costs, reduction in administrative cost, improvement in on time delivery and improvement in inventory turnout. So If you are still questioning whether your company really does need an ERP system feel free to contact me on Linkedin or tweet to me and I will try to help you or get you connected with one of our experts at Mazikglobal.