Document data sources for document templates for Dynamics AX 2012

Introduction

In the previous blog (Document template libraries for Dynamics AX 2012) we showed how a document template can be created so that Word and Excel documents can be generated from within Dynamics AX – and the generated document contains data from the selected Dynamics AX record.

You link your document template to Dynamics AX by selecting a Document data source:

So you may have wondered where the document sources are managed and whether they can be customised.

The answer, of course, is yes to both.

Document sources

Go to Organisation administration > Setup > Document management > Document sources:


You’ll see that there are three types of document sources:

‘Service’ document sources can be used to update Dynamics AX via the Microsoft Office Add-in – they’re a bit too technical for me, so we’ll pass over them for now.

‘Query reference’ is a query that can be used by the Microsoft Office Add-in for reading Dynamics AX data (read only).

‘Custom query’ is a filtered view of a query.

Creating new queries isn’t terribly difficult but a quick glance at the AOT shows you that there are already hundreds of queries defined in Dynamics AX:

To add one as a document source just click the New button:

Select your module from the drop-list.

Choose the Data source type ‘Query reference’ and enter/select the name of a query:

Then enter a description.

Click ‘Activate’ and you’re done.

Open Excel (or Word). Log into Dynamics AX and click “Add data’ > ‘Add data’:

Your new document source shows up. Tick to select, and OK:

The Fields pane shows the fields in the records defined for the query:

In Excel drag them to your worksheet (or double-click on a field):

When you’re done, close the Fields pane, and click ‘Refresh’ to read Dynamics AX:

Pretty neat.

Now, let’s say that you want to make things easy for your users by filtering this data.

Back on the Document data sources form click New again, select a module, and this time select ‘Custom query’ as your Data source type:

Again select/enter your query. This time, as you tab out of the Data source name field a filter query form opens:

You know what to do. Define your filer criteria and click OK:

Finally give your customised query a Description, and Activate it:

Back in Excel:

As before:

But this time, of course, I only see the retail customers (Customer group = 30).

I like it.

Advertisements

Document template libraries for Dynamics AX 2012

Introduction

The Dynamics AX document handler has always been able to generate Word (or Excel) documents using Dynamics AX data (and that functionality still exists) but this functionality was extended and made easier to use in Dynamics AX 2012.

Template library

‘Template libraries’ are a new document type introduced in Dynamics AX 2012.

Go to Organisation administration > Setup > Document management > Document types and define a new document type (if required):

A Template library is a shared folder on a SharePoint site. You define the folder to be used in the Document templates fast tab which becomes visible when you select the Class ‘Template library’.

The standard demo Hyper-V Enterprise portal site includes a Shared directory. I created a new Shared folder and set the SharePoint site address and selected my folder:

Create a template

Open Word, and log into Dynamics AX using the office add-in:

Use the Add data button to add a document source:

The Fields action pane will show you all of the fields (and linked tables) from your data source.

Create your document template and add fields by dragging them into the template:

When you’re done, save the template as a normal word document (not a template) in your Template library folder:

Back in Dynamics AX, on the Document types form click ‘Synchronise’:

You can see that the system’s recognised the Primary table from the data source.

Now Activate the template:

Use the template

You’ll need to be on a form related to your ‘Primary table’ (Quotations in my case). This form has got a ‘Generate from template’ button and that shows the active templates linked to the form/table:

Click that option and the system opens word, creates a word document attachment linked to the selected record, and populates the fields on the template:

The document’s added as a Document handler attached document:

On the Document Handler, notice that the New button includes the template as an option (and this is how you add template documents when there’s no ‘Generate from temple’ option available on the main form):

Neat eh?