Donatas
Donatas

Reputation: 421

Reading user's information in Active Directory from Dynamics AX using specific domain controller

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?

Upvotes: 0

Views: 863

Answers (2)

Alex Kwitny
Alex Kwitny

Reputation: 11544

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");

Upvotes: 1

Alex Kwitny
Alex Kwitny

Reputation: 11544

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

Upvotes: 2

Related Questions