Access D365 FinOps Services with OAuth 2.0

So before we jump in how to, we need to understand some basics how OAuth2 works.

well basically OAuth2 is one of the authentication out there, the purpose is to is validate and authenticate with Azure AD, permission granted or not to access the apps. if granted, it will generate “TOKEN”.

now we heading to D365FinOps , in D365 FinOps we have users and all of its security roles, so basically user that can call D365FinOps services (example OData or Custom Services) via OAuth 2.0 should be only legitimate D365 FinOps users.

There is some grant_type for OAuth 2.0 that works with D365 FinOps :
1. Authorization Code : when user access or call some services, they need to provide login information . (works with D365 FinOps, just provide user and password when microsoft login window popup) , then TOKEN generated.
ref :

2. Password Credentials : the user and password credentials is hardcoded in the call, so no popup window login, then TOKEN generated afterward.
ref :

other grant_type seems not working wih D365 FinOps because cant provide legitimate D365 FinOps User in the call parameter.

Now let us try shall we ??
the summary for the tutorial (will update in next blog post) :

1. Setup Apps Registrations in Azure AD and Setup in D365 FinOps
2. Generate Oauth2 Token using grant_type Authorization Code
3. Generate Oauth2 Token using grant_type Password Credentials
4. Testing OAuth2 Token to call OData Services
5. Create Simple D365 FinOps custom services
6. Testing Oauth2 Token to call D365 FinOps custom services.


Starting Dynamics AX for Retail (POS Development)

One of the most challenging on dynamics AX is to develop POS on AX Retail module.

The Dynamics AX for Retail POS application was designed base on .Net Application using C# language so it’s little bit odd for regular AX technical who always develop using  X++, so since the POS is not using standard AX MorpX so we need to prepare to develop POS.

  1. Visual Studio for development tools.
  2. Dev Express License (Optional for better touch GUI)
  3. Retail SDK (POS Source Code)

Let’s  jump   into number 3. I assume you already have visual studio on dev server.

You can found Retail SDK on Dynamics AX Installation.


After installation finished you can found the source code  on document folder.

Source Code

For very first time lets  focus at the two folder on the POS Plug-ins, there is Services and Triggers because almost all POS function source code is on that folder.

Services: Services are actually .Net assemblies. POS implements many of the features as services using interfaces and can be modified using Visual Studio. POS loads these services at run time by calling the interfaces. So whenever you modify or extend the standard service keep the assembly name same as original so that POS can recognize it and call it at run time.

Triggers: Triggers are called before and after the operations. There are two types of triggers, Pre-triggers and Post-triggers. Pre-triggers provide a way of validation before a certain operation is executed. Post-triggers are used to respond to an operation after it has finished. You can modify the triggers same way as services.

*I use Dynamics AX 2012 R3 CU8 on this tutorial, also work for AX 2012 Feature Pack, AX 2012 R2, and AX 2o12 R3.

Create Custom Script

So first lets open the Triggers folder and double click Triggers.sln file, you will show all the triggers source code now expand on visual studio, lets pick our first function to modify.

For this tutorial we will add some function when POS starting, so lets’s open ApplicationTriggers Project and open  ApplicationTriggers.cs , at this class you will found the some of methods, this methods will be calling when POS staring, for example  ApplicationStart, ApplicationStop, PreLogon, PostLogon and etc.

Try to add some code at ApplicationStart method, i assume this method will be calling when POS application starting, lets add some simple script at here, let’s try add some dialog box.

 public void ApplicationStart()
     //Our Custom Script
     MessageBox.Show("POS aplication starting....");

     string source = "IApplicationTriggers.ApplicationStart";
     string value = "Application has started";
     LSRetailPosis.ApplicationLog.Log(source, value, LSRetailPosis.LogTraceLevel.Debug);
     LSRetailPosis.ApplicationLog.WriteAuditEntry(source, value);

To make the script running on the POS we need to build the project in to dll and copy the dll on POS folder.

Try to run your POS, and the message box will be showing when POS starting.

Deploy Custom Script/dll

You should copy all  custom *.dll files on the Extensions folder at Retail POS Folder. Don’t replace the original ones.

We can using two different Extensions Folder on POS .

1. Retail POS\Extensions

Source Code2. Retail POS\Services\Extensions

Source Code

Always use the first one for custom Triggers *.dll, and second one for Services *.dll to make it easy to remember and maintenance.

Lets Starting To Debug POS Custom Code.

For debug the code, we can change some properties on the visual studio project,  use our first sample project, right click on that project and chose Properties.

First open Build  Tab on Properties UI and select the Output Path because this is Triggers so i  select “C:\Program Files (x86)\Microsoft Dynamics AX\60\Retail POS\Extensions\” Folder.

Source Code

And than open Debug tab, at the Start Action group select Start external program and select your POS.exe file.

Source Code

just put your break point on your custom script, and run the project using F5 or Start Button. Lets see the magic happen.

*Note: You can copy all POS Folder to your own folder to make the  original POS Files safety.

add new default dimension (financial dimension) on new table and form example tutorial

This example tutorial will guide you to add new default dim on table and forms.

1. Add new field with type Int64 and set the properties.

2. Add relation on table relation and set the properties.

3. on class declaration form , add code below :

public class FormRun extends ObjectRun
    DimensionDefaultingController   dimensionDefaultingController;

4. add tab page Financial Dimension on form design , and set properties like img below

5. on TabFinancialDimensions , override method pageActivated

public void pageActivated()


6. on init form, like code below :

public void init()
    dimensionDefaultingController = DimensionDefaultingController::constructInTabWithValues(true, true, true, 0, this, TabFinancialDimensions, "@SYS138487", curext());
    dimensionDefaultingController.parmAttributeValueSetDataSource(HRSJobPowerPlan_ds, fieldStr(HRSJobPowerPlan, DefaultDimension));

7. finnaly, on datasource form method override method :
on active()

public int active()
    int ret;

    ret = super();

    return ret;

on write()

public void write()

on delete()

public void delete()

8. preview example form: