Tuesday, September 16, 2014

Send tweets from AX via the Retail module

Once again I fell over some objects with interesting names in the retail code. This time I learned that you can update Twitter and Facebook from AX.

In the following I'll describe the Twitter setup.

First of all, you need to setup an application under your Twitter account. Go to https://apps.twitter.com/ to do that. Under settings, you need to fill in:
  • Name: This will be the name of your application. Mine is called PalleAgermarkTest.
  • Description: This shows when for example you later on link the application to be able to use your Twitter account.
  • Website: This should a website where users can download the application. Since I don't have a real application, I have just put the address of my blog.
  • Callback URL: This is needed when AX links the application to your Twitter account. Again, the address is not important (but an address is needed) for this demonstration and I have again put the address of my blog here.
On the API tab of the setup, you'll get an API key and an API secret. You will need these in AX.

On the Permissions tab, give the application write access to the Twitter accounts that sign up to the application:

That's it for Twitter.

Go to Retail \ Setup \ Parameters \ Retail parameters to setup some seed data for the retail module. Click the Initialize button:

Now in AX, go to Retail \ Setup \ Parameters \ Retail shared parameters and enter the API key secrets from above:

Then go to Sales and marketing \ Setup \ Campaigns \ Media types and add Twitter as a media type:

Now when clicking the Link account button, you should get the option to link your Twitter account (the screen clip is in Danish, but you should be able to get the idea):

So now all the bits and pieces are setup, and a very simplified piece of code like this example is able to post to Twitter:

static void Tweet(Args _args)
    smmCampaignMediaTypeGroup           mediaTypeGroup;
    RetailMediaChannelConnectorSettings settings;
    RetailMediaChannelTwitterConnector  connector;
    RetailMediaChannelMessage           message;

    select firstOnly TableId from mediaTypeGroup
        where mediaTypeGroup.CampaignMediaTypeDescription == 'Twitter'
    join settings
        where settings.smmCampaignMediaTypeGroup == mediaTypeGroup.CampaignMediaTypeId;

    connector = RetailMediaChannelTwitterConnector::construct(settings);
    message = RetailMediaChannelMessage::construct();
    message.parmMessage("Tweet from AX");

The result:

Saturday, September 13, 2014

Dimension Defaulting on MSDN blogs

The Microsoft Dynamics AX GFM team have written up a great seven part series about dimension defaulting. Read it here: http://blogs.msdn.com/b/ax_gfm_framework_team_blog/archive/2014/09/12/dimension-defaulting-part-1-financial-dimensions-discovery.aspx

This would really have been helpful information to get when this new framework was released, but better later than never I guess.

Thursday, September 11, 2014

Normalization pattern for custom fields in separate table

When you need to add fields to standard tables, you can choose to add them to a new linked table rather than to the standard table.

If you do that, you might find the pattern for normalization for county/region fields useful.

Have a look at the White Paper "Adapting your code to table normalization for country/region fields in Microsoft Dynamics AX 2012 R2"

Thursday, August 28, 2014

My new best friend: Set-AXModelStore -InstallMode

I'm working on an upgrade from AX 2012 R2 to AX 2012 R3, and during the initial work upgrading the code I experience from time to time that the client crashes. To be fair we probably have modifications in places we shouldn't have them, though I have removed the worst before starting the upgrade.

The problem is that when I restart the client, I get an empty workspace and the menu item to open a new development workspace is disabled.

Panic sets in and my pulse rate gets alarming high, but...

Manually setting the model store in installation mode again and restarting the client opens the "The model store has been modified" dialog and I'm able to open a development workspace again.

So if that happens to you, try to open the Microsoft Dynamics AX 2012 Management Shell and enter the command "Set-AXModelStore -InstallMode".

Tuesday, August 26, 2014

Dynamics AX learning paths

Here is a really cool document i found on a danish Microsoft site. It gives you a good overview of AX training for whatever role you are in.

Download it here from my OneDrive.

Tuesday, August 19, 2014

Spelling errors in Office Add-In can cause wrong value substitution in table columns in R2

When you create a Word template with the Office Add-In and Word for some reason marks field names  in your columns as being misspelled, these columns aren't getting their names properly replaced with actual values when you merge the template into a document with values.

You can reproduce the problem by going through the following steps on for example a standard AX 2012 R2 demo machine.
  1. Make sure your AX user is setup to run en-us as language.
  2. Make sure that you in Word have at least one other proofing language than en-us installed.
  3. Make sure that Word uses en-us as the default proofing language.
  4. Go to Organization administration / Setup / Document Management / Documents data sources.
  5. Add the SalesLine query and activate it.
  6. Open Word.
  7. Add some text in top of the document, just to make some space to the table you are about to insert.
  8. Insert a table with two rows and five columns.
  9. Go to the Dynamics AX tab and click Add Data.
  10. Select the data source you started out setting up.
  11. Add the following fields.
    • Sales order
    • Item number
    • Quantity (ordered quantity)
    • Unit price
    • Net amount
  12. Save the document and run a Merge.
  13. That should look ok.
  14. Go back to the template, select all with Ctrl-A and change the proofing language to something other than en-us.
  15. Run a spell-check and check that it finds supposed spelling errors in your column names.
  16. Save the document and do a new Merge.
  17. Now things don't look alright.
Some screenshots:
The template

The first well done merge

The template with the new proofing language and after spell check
The not so well done merge

There are some workarounds:

  1. Keep you fields names to just on word.
  2. Run a spell-check of the template and choose to ignore all spelling errors in fields names, making the squiggly lines disappear.
  3. Use a speciel Word style, which set up to not being checked for spelling errors, for the fields.
  4. Sometimes just shortening the name of the field in the table helps; for example from "Item number" to just "Item".
Well, it is an odd issue. But now you know a probable cause if you run into it.

For some KB2904824 should fix the issue. I havn't had any luck on my systems though.
I can't reproduce the issue in R3, so it must be fair to assume that is has been fixed for R3.