• About

Day 2 Day Dynamics

~ Experiences of a working AX developer

Day 2 Day Dynamics

Monthly Archives: October 2015

Refresh-AXServices custom PowerShell function

23 Friday Oct 2015

Posted by John Hagler in Powershell

≈ 1 Comment

Tags

AIF, Application Integration Framework, Automation, AutoRun, AX, AX 2012, AX Services, PowerShell, R2 CU7, RegisterServices

Now that we have a working build, I’m going to be focusing on the functions that I use to manage my environment and code pushes. I will be releasing these functions as both stand-alone functions and to the D2DDynamics module.  You can integrate them into your environment either way.

The Refresh-AXServices custom PowerShell function allows you to automate service refresh functionality in AX.  This function looks just like all of the other functions that use Start-AXAutoRun.  It is a template you will see over and over again.

The process it is automating is navigating to the Services node in the AOT, expanding the node and then right clicking on a service and choosing Add-ins -> Register services.

RegisterServicesAlt

This process opens an AIF Services form that allows you to see information regarding your AX service classes.  It also has a button to allow you to refresh your services when there are code changes.  This is the process that is automated.

ServicesReresh

The Refresh-AXServices function takes between 1 and 7 parameters:

  • ConfigPath (Client configuration for the chosen AX environment)
  • LogFile (The value defaults to the temp folder but can be overridden if desired)
  • TimeOut (The value defaults to 30 minutes but can be overridden if desired)
  • SMTPServer (SMTP server to use to send the email)
  • MailMsg (Net.Mail.MailMessage object used to send the email)
  • AXVersion (The AX version.  It defaults to 6.)
  • VariablePath (Path to a file used to default the parameters/variables)

I use the VariablePath parameter the same way that I do in the other functions I’ve posted that use it.  This function can be found in Codeplex.  The steps of this function are:

  • Load the variables if a VariablePath parameter is used
  • Get the AX environment info using Get-AXConfig
  • Get the AIFServiceGenerationManager::registerServices AutoRun xml using the Get-AXAutoRunXML function
  • Call the Start-AXAutoRun function to refresh the services

This function uses the ability that the AutoRun process has of calling static methods in AX.  While this particular function is being used to call the AIFServiceGenerationManager::registerServices() static method, AutoRun allows you to call any static method inside of AX.  If you get really creative with it, you can build your own static methods inside of custom classes to automate non-static method processes inside of AX.  The AutoRun functionality is very powerful and can probably be used to automate just about any process inside of AX.

This function should also only be run on the AOS server.  It has been tested using AX 2012 R2 CU7 but will probably work for other versions.

Understanding the Build-AXModel function

08 Thursday Oct 2015

Posted by John Hagler in Powershell

≈ Leave a comment

Tags

Automation, AX, AX 2012, AX Build, Build Scripts, Dynamics AX, PowerShell

I’m going to start off with how I set up TFS for a build.  I have my main code branch in TFS, D2D_AX_DEV, that is used for all of my development environments.  Each AX development environment has TFS setup and pointed to this code branch.  I have also set up a branch off of D2D_AX_DEV called D2D_AX_REL.  This is my release branch.  I merge everything into the release branch that is going to be included in the build.  I then point my build function to the release branch.

The Build-AXModel function is broken up into 5 sections:

  1. Outer section at the beginning and end that set up the variables passed through the parameters and that email start and completion of the function.
  2. Set up build variables: This section uses variables in the Build-AXModel_Variables.ps1 file that is passed in through the VariablePath parameter to set up the environment for the build and model export.
  3. Prep build environment:  This section restores the AX environment back to a vanilla instance for the build and gets TFS and the combined .xpo file ready.
  4. Import/Compile AX (Main build step): This section pushes the TFS code into the build environment and compiles/syncs everything and gets the environment ready for a model export.
  5. Export model: This section exports the model file into your build folders.

The individual steps and explanations for what they are doing can be found in my earlier posts.  I have done some things in my Build-AXModel_Variables.ps1 file to make this more of a generic process to be re-used however and I would like to clarify what I’m doing.

There are multiple places in my build function where I loop to allow functions to work on different layers and models (model creation, .xpo creation/import, label file import, VS Project import and model export).  In my original process this wasn’t necessary as I only build one model in one layer.  The way it is currently built however, allows for multiple layers and models.

I handle this looping process using foreach statements and ArrayLists in my variables.  I used ArrayList vs array as the behavior with ArrayLists was a lot more dependable when looping.  It is a simple construct.  I build variables for the individual parameters needed for a function call.  I then build an ArrayList to hold grouped variables for a function call that will allow me to loop through an ArrayList of my grouped ArrayLists and call the function multiple times.  My loops are only through the VAR layer and for my D2D model but you can easily add more variables for layers and models to these ArrayLists to allow multiple function calls.  Make sure you build your ArrayLists in the order in which you want to process the layers and models.

ArrayListEx

The area that is most likely to need customization to fit your specific build are the steps in the “Import/Compile AX” region.  You may need to change the order of the server/node compiles or change the server compile to a client compile.  You may also need to change the function used to import the VS Projects and add some node compiles if you have some complicated dependencies.

As I said in the blog post covering the function, I’m not planning on putting this function into the module because of the likelihood that you will need to modify it to fit your needs.  I’m hoping that some users will be able to use it out of the box but I’m sure there are some who will need to make changes.  The steps in my version of the function fit the current needs of my build process.

Follow Day 2 Day Dynamics on WordPress.com

Day 2 Day Dynamics

  • RSS - Posts
  • RSS - Comments

Follow me on Twitter

My Tweets

Recent Posts

  • Minimizing Database Calls
  • Push-AXModel custom PowerShell function
  • Clean-AXModel custom PowerShell function
  • Get-AXTFSCombinedXpo custom PowerShell Function
  • Refresh-AXAifPort custom PowerShell function

Archives

  • February 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015

John Hagler

John Hagler

John Hagler

I am the Dynamics AX Technical Architect at Dealer.com. I have been working with AX since Sep. 2006, starting with Axapta 3.0. I have worked as both a VAR and an AX customer.

View Full Profile →

Blog at WordPress.com.

  • Follow Following
    • Day 2 Day Dynamics
    • Already have a WordPress.com account? Log in now.
    • Day 2 Day Dynamics
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...