0

We have a few domain controllers that can be used to read AD users information.

When domain name "mydomain.co.uk" is being used as AD domain, any of those few domain controllers are being picked to serve the purpose.

However, if changes in AD haven't been propagated across all domain controllers, no results are being returned.

To address the issue I've decided to always point to a specific domain controller, which is "dc1.mydomain.co.uk".

In C# that's easily done with something like this:

new PrincipalContext(ContextType.Domain, 
                    "dc1.mydomain.co.uk:389", 
                    "OU=Groups,DC=mydomain,DC=co,DC=uk", 
                    domainUsername, 
                    domainPassword)

However in X++ only "mydomain.co.uk" works:

static void validateDomain(Args _args)
{
    xAxaptaUserManager          Axmanage;
    NetworkDomain               networkDomain = "";

    // Works
    networkDomain = "mydomain.co.uk";

    // Does not work
    networkDomain = "dc1";
    networkDomain = "dc1.mydomain.co.uk";
    networkDomain = "dc1.mydomain.co.uk:389";
    networkDomain = "LDAP://dc1.mydomain.co.uk:389/";

    Axmanage = new xAxaptaUserManager();

    info(strFmt("%1", Axmanage.validateDomain(networkDomain)));
}

How can I achieve same functionality with xAxaptaUserManager in MS Dynamics AX 2012 R3, if possible?

Donatas
  • 317
  • 1
  • 5
  • 18

2 Answers2

2

We're not on your network, so we can't really test everything, but if xAxaptaUserManager, which is a kernel class doesn't work, but you are able to do it in C#...just create an assembly "helper" that you call from AX.

See below links:

https://learn.microsoft.com/en-us/dynamicsax-2012/developer/how-to-add-a-reference-to-a-net-assembly

https://learn.microsoft.com/en-us/dynamicsax-2012/developer/net-interop-from-x

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • Thank you @Alex - I was hoping I will be able to avoid it as [making many calls to managed code from AX is not recommended](https://blogs.msdn.microsoft.com/x/2011/12/07/when-to-use-managed-code-in-dynamics-ax/), but it would be ok solution if nothing can be done from X++ itself. – Donatas Jul 10 '19 at 22:01
  • @Donatas your article actually says `C#` is a favored choice under `Integration with 3rd party tools.`. Also, the function the assembly would perform is ideally small and purpose built. That article was also written in 2011, when the direction Microsoft was taking with `AX` was unknown, and Microsoft wanted to discourage `C#` developers from writing lots of business code in `C#` then calling it from AX. We know now that you'll probably be using Azure AD with 365 and whatever you're doing with the domain lookup will need revisited anyway. Why do you need to validate the domain? – Alex Kwitny Jul 10 '19 at 22:17
  • Also, have you tried `info(new xAxaptaUserManager().getFQDN('YourDomain'));` – Alex Kwitny Jul 10 '19 at 22:21
  • Thank you @Alex. I shall move all that logic to the managed code. It's not that I'm against it, I just was hoping I can do it in AX itself with the tools already there. I'm normally using `xAxaptaUserManager.getSIDFromName("domainUser", "mydomain.co.uk", UserAccountType::ADUser);` line to get AD user details, but if I use specific domain controller here, I get _"Error in getting SID"_. `getFQDN("dc1.mydomain.co.uk")` throws _"Could not obtain Fully Qualified Domain Name for the domain..."_ error. – Donatas Jul 11 '19 at 07:49
1

I should have said this before, and you may prefer this as a solution.

In AX, you can just call .NET code. I think you may have to put this in a server method in a class or table if it doesn't work right away.

System.DirectoryServices.AccountManagement.PrincipalContext     principalContext =
        new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType::Domain,
                                                                        "dc1.mydomain.co.uk:389",
                                                                        "OU=Groups,DC=mydomain,DC=co,DC=uk",
                                                                        "username",
                                                                        "password");
Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71