The Infolog

A blog of Dynamics AX development tips and tricks

Skip to: Content | Sidebar | Footer

Reprinting invoices using printJournal

29 August, 2014 (14:12) | Dynamics AX, SSRS | By: Howard Webb

If you need to reprint a sales invoice there is a method on the CustInvoiceJour table called printJournal. Calling this method will print using the original print management destination but you can override the destination by passing in an instance of SalesInvoiceJournalPrint. Below is an example of calling it and forcing the print destination to be the print management destination:

 

Counting the number of records in a query/query run

17 August, 2014 (15:53) | Dynamics AX | By: Howard Webb

Hi,

 

This post is more for my memory more than anything else. If you need to get the number of records returned in a query or a query run you can use the following method:

SysQuery::countLoops(QueryRun)

 

This will return the same result as looping through the query using queryRun.next()

Printing external customer statements to multiple file names

10 June, 2014 (11:02) | Dynamics AX, SSRS | By: Howard Webb

One of our customers produce multiple PDF files for external customer statements. They wished to rename the file with the customer account number. To do this we have edited the following method:

 

\Classes\CustAccountStatementExtController\runPrintMgmt

 

I declared the following variables

 

To make sure that I get just the file name correctly I have used the global method fileNameSplit which returns a container, hence the outputLocation variable.

 

The code used was inserted at line 120, just before the output reports call.

 

 

This will override what the end user puts as a file name with the account number as this is what the customer wanted, however we could easily change line 125 to account for appending the file name.

Using date effective tables in a view

7 May, 2014 (14:13) | Dynamics AX | By: Howard Webb

When writing a select statement or using a query you do not have to worry about if the table is a date effective table or not, the frame work handles this for you and will as default return the record that is current. If you are using a view however you need to do a bit more work to get your view to get a single record out.

 

Firstly you need to locate the date effective table in your view and then move the ValidTo and ValidFrom fields in to the fields list:

 

 

With that done. Bring up the properties of the view and at the bottom you will see the following which you need to set to yes:

 

 

This will make your view respect the date effective settings on the table.

 

 

Please note: you will only see the effects of this within the form, not within table browser.

Display/Edit method caching

4 March, 2014 (10:54) | Dynamics AX | By: Howard Webb

When developing a new form or a new table that will have display or edit methods we should be thinking about how costly these types of methods are. Adding lots of these methods to a form can cause a large delay in opening and refreshing as these methods are recalculated every time a refresh is triggered on the form, which can occur when the user edits fields, uses menu items, or presses F5. We have a few options to allow caching of these methods, which can ease the number of round trips to the database.

If the method is declared on the table we can use the cacheAddMethod on the datasource to force the values to be cached. Using this method allows the form build engine to do all of the calculations for the methods in one round trip to the server saving time.

To do this we should call the method on the init of the datasource where the method lives. An example of this can be found on the SalesTable form. The SalesTable table has an edit method called editContactPersonName. This is used in the SalesTable form, however as the form has a lot going on the method is cached. The call to this method can be found in the init of the datasource:

 

We can also add caching to the control itself within it’s properties. There is a property called CacheDataMethod just under the datamethod which allows you to set the caching:

 

The settings for “Yes” and “No” are self-explanatory, Auto will cache the data method only when the form datasource is read-only.

Drill through on SSRS reports.

28 February, 2014 (15:48) | Dynamics AX, SSRS | By: Howard Webb

Drill through links in SSRS are controlled by C# code which produces a URL that can be processed to call AX which can open a form with the appropriate record. There is a common class (DrillThroughCommonHelper) that will need to be either referenced or modified if you would like to use a lookup in Your SSRS report. Firstly I would suggest that you open up the C# project to see if your lookup is already there.

 

Firstly navigate to \Visual Studio Projects\C Sharp Projects\SRSDrillThroughCommon and right click and select edit on the C# project. This will open it up in Visual Studio and you can open up the C# code. With the C# code open in the editor you can search for the EDT of your field or the form to find the correct method to call. In my example I was looking to use SalesId. A quick search for SalesId found a method that was already written that would produce the lookup.

 

 

If a custom method is needed you can use that as an example on how to produce the lookup, but in a nutshell there is a static method (GetDrillthroughUrl) that accepts the MenuItem that launches the form and the table, field and field value of the record you wish to open the form with.

With that method either found or created you can now reference that in your report. The first step is to create or add the C# projects to your report. With your report open in VS, add a new data method. With that done VS will add a new business logic project to your report project:

 

Next open up the AOT view within VS and find the C# project (\Visual Studio Projects\C Sharp Projects\SRSDrillThroughCommon) we opened earlier and double click on it which will add this to your overall project. With the project added now expand the business logic project and right click on the references node. Select “Add reference” and in the projects tab you will see the SRSDrillthrough project, select that.

 

You can now finish up the display method :

 

With this done you can now reference the new display method in our field, allowing the URL to be built. Locate the field in the report design and open up the properties of the text box. Select the action tab.

 

 

Select the URL radio button and put the following call to your display method in the expression (in this example the field is SalesID and it is located on the data set SalesInvoiceHeaderFooterDS)

 

Please remember to set the font colour as the SSRS report renderer does not change URLS colour automatically.

 

 

Navigation links within a SSRS report

27 February, 2014 (16:38) | Dynamics AX, SSRS | By: Howard Webb

If you are developing a larger auto-design report which groups data together it might be worth adding document navigation to the query to allow the end user to jump between sections of the report:

 

 

To do this you will need to set up grouping on your table to allow the jumping. The label of the grouping will need to be the value you want displayed (in this example the customer account:

 

Then on your table definition You can then set data navigation style property to “DocumentMap” and this will add the navigation pane to the report:

 

 

Google maps mini-map for customers

10 October, 2013 (14:04) | Dynamics AX, Uncategorized | By: Howard Webb

I wanted to move some of the google maps work I did in AX 2009. One of the bits I did originally was to produce a mini map in the customer screen:

 

I decided to fit better with 2012 I have moved it to a factbox. To create a fact box first you have to create a form design. In 2009 I used an Active X control (browsercpm) as it gave me more control over the browser window, however in AX2012 this is no longer present but there is an Active x control called “Microsoft Web Browser” which contained most of the same methods so I moved it to that. The form design is relatively simple, however I found out you need a datasource on a fact box as there is no method that is called between record switches unless you link a datasource. In the active of the data source I call my method. The form looks as follows:

 

 

And the custom methods are as follows:

 

public
void getGoogleMap()

{

CustTable custTableLocal;

Args args;

;

 

args = element.args();

 


if(args.record())

{


if(args.record().TableId == tableNum(custTable))

{

custTableLocal = args.record();

element.createURL(custTableLocal.postalAddress().ZipCode);

}

}

}

 

public
void createURL(Addressing _address)

{

 


str mapUrl;

;

 

mapUrl = #MiniMapURLStart;

mapUrl += GoogleMapsHelper::formatAddress(_address);

mapUrl += #MiniMapURLEnd;

MiniMapControl._Height(210);

MiniMapControl._Width(210);

MiniMapControl.Navigate(mapUrl);

}

 

I also have a macro to containing the start and end of the URL:

 

#define.MiniMapURLStart(‘http://maps.googleapis.com/maps/api/staticmap?center=Burnley, United Kingdom&zoom=4&size=200×200&markers=color:red|’)

#define.MiniMapURLEnd(‘&sensor=false’)

#define.MiniMapURLSeperator(‘&markers=color:red|’)

 

 

Along with a static method to format the address (I have used just the postcode due to issues with the data but this should format the full address correctly)

 

public
static
str formatAddress(Addressing _addr)

{


str ret;

;

 

ret = _addr;

ret = strReplace(ret, ‘ ‘, ‘+’);

ret = strReplace(ret, ‘\n’, ‘,’);


return ret;

 

}

 

 

And then to finish off the fact box a menu item and a form part.

 

finished result is:

 

 

 


 


 

SSRS error in AX2012 – An item with the same key has already been added

9 October, 2013 (10:13) | Uncategorized | By: Howard Webb

One of our customers have been having this issue. Microsoft say it is down to a cache issue with SSRS. Most places say that a restart of the AOS and of SRRS along with a re-deploy will fix it. I have managed to get this working with either just a SSRS restart or a clearing of the AOS cache and then a redeployment of the report limiting downtime. In addition it has been reported that multiple deployments of the report can fix this issue.

 

http://blogs.msdn.com/b/axsupport/archive/2012/03/13/ssrs-error-in-ax2012-an-item-with-the-same-key-has-already-been-added.aspx

Using AIF services

30 September, 2013 (13:46) | Uncategorized | By: Howard Webb

Here are the steps to get AIF up and running and accessible. In this example I have created an excel add-in to pull on hand information for items.

 

Create a port

 

Firstly you need to create a port to allow access to your data. There are two ways of creating a port, you can either create an advanced port (which gives you a lot more control) or create one by using service groups. I have used the advanced option but tagged on the end of this is a quick summery on creating a service group.

Open up an AX client and browse to System administration/setup/Services and Application Integration Framework/Inbound ports:

Click on new, giving the port a name, description, etc.AI

 

 

Click on “service operations” and then select the services you wish to expose, in this case we are using inventInventoryOnHand:

 

 

Next set the data coming out in the XML by selecting the “customise documents” check box and then clicking on the “data polices” button. This lists the fields your XML document will have in it, it is advisable to remove any you do not need to keep the file size down:

 

 

You can also set things like extra security and logging but they are not needed in the scope of this.

 

With the port fully setup click activate and the port should then activate. This will give you a new field – WSDL URL which will be the service URL:

 

You can now check that your service is accessible by pasting the URL in to a browser (You should get an XML file returned – the xsd).

 

Adding a display method

 

I had also wanted to use a display method which was not originally setup – in this case the item name. After a lot of issues I have managed to set this up.

Firstly add a new Parm method to the AX table class (AXTableName) which will return the value you wish to use:

 

 

Save and compile this new method. Next go to tools ->Application Integration Framework -> Update service. Update the service that you will be using making sure to update the classes:

 

 

This should then automatically create a project and the correct parm methods for you:

 

 

If you are using a service group the xds should now be ok, however if you are using an advanced port I have found it better to open up the data polices and make sure that the extra field is there.

Using the service

 

I have created a small Excel add-on in C# which will pull all of the items and how many are in stock and them move that information in to an Excel spread sheet.

To use the service you will first need to add the service reference in the project. To do this you use the url. Once this has loaded correctly you can call your service and get data out. I will attach the Visual Studio project that I created

 

Creating a service group

 

Create a service group by opening up the AOT, browsing to ‘Service Groups’:

 

Select the services you would like to access and drag and drop them in to your new service group:

Right click and then select deploy and your service will have a port setup in the Inbound port settings.