D365O. X++ objects equality.

balance

There are two different kinds of equality: equality by reference and equality by value. I’m not going to explain these basic concepts here, because you can find tons of information in the web, today I want to show how you can implement value based comparison in X++.

By default AX uses reference check. In previous versions we could override equal method of the Object class to implement value based comparison, however, we have to explicitly derive new class from Object, because it was not derived by default and equal was not called by AX (as far as I know). For example, if you wanted to use value equality with collections, like set, you had to workaround using map where key is combination of fields and value is object itself.

With new version of AX we moved to .NET world where X++ is almost a first class citizen. Why almost?  There are bunch of limitations and not implemented features like generics, but we slowly getting there.

Let’s get back to value equality. Now, each class is derived from System.Object. System.Object has Equals and GetHashCode methods used to check equality that we can override. Again, there are lots of info in the web about these two methods and guidelines how to override them, so I’ll jump straight into the example.

I have a new class with two public fields:

class MyClass
{
    public int a;
    public int b;
}

In my test job, I want to store instances of MyClass in a set. Set should contain only instances with unique combination of a and b values.

public static void main(Args _args)
{
    MyClass myClass1 = new MyClass();
    myClass1.a = 5;
    myClass1.b = 10;

    MyClass myClass2 = new MyClass();
    myClass2.a = 5;
    myClass2.b = 10;

    Set set = new Set(Types::Class);

    set.add(myClass1);
    set.add(myClass2);

    info(int2Str(set.elements()));
}

As we already know, AX will add 2 elements into the set because it always performs reference check by default.

Let’s override Equals and GetHashCode using MSDN guidelines

public int GetHashCode()
{
    return this.a ^ this.b;
}

public boolean Equals(System.Object _obj)
{
    if (_obj == null)
    {
        return false;
    }

    if (System.Object::ReferenceEquals(this, _obj))
    {
        return true;
    }

    if (!this.GetType().Equals(_obj.GetType()))
    {
        return false;
    }

    MyClass compareTo = _obj;

    if (compareTo.a == this.a && compareTo.b == this.b)
    {
        return true;
    }
    else
    {
        return false;
    }
}

It’s just an example how “standard” features from .NET could be used in X++. Moving forward, you can expand this example implementing IComparable interface, so new class could be added to any standard .NET collection and be sorted! But it’s a topic for another blog.

D365O. Issues with Microsoft Dynamics App for Office setup.

Recently I’ve helped my colleague to setup Word Templates for D365O. We followed Office integration tutorial on the wiki, but it has few gaps.

First of all, it’s not clear where to find share that contains the Microsoft Dynamics App manifest ( step 1.d). Use base URL for the cloud environment, for example, https://topo00dfa4stbobaos.cloudax.test.dynamics.com/

Second step where we stuck for a while is not so obvious. 4.b says that you need to select Template Designer after loading applets. However, there was nothing to select. To fix this issue you actually need to go to D365O -> System Administration -> Setup -> Office app parameters and on “Registered applets” tab check that there is a record for Microsoft.Dynamics.Platform.Integration.Office.WordDesignerApplet in a grid. 

OfficeAppParameters.jpg

If it’s not there click on “Initialize applet registration” button and AX will auto populate the grid.

 

D365O. How to deploy Demo VM using Visual Studio subscription.

Many of us have Visual Studio subscription (formerly called MSDN subscription) and there is monthly Azure credit coming with it. It could be used to spin up D365O demo VM, but the whole process is not straightforward. I would describe it step by step today.

  1. Activate monthly Azure credit. You will get an email with subscription id after completion.ActivateSubscription.png
  2.  Go to Azure portal where you can check details of new subscription.AzurePortal.jpgAzurePortalSubscription.jpg
  3. Different types of subscriptions give you different amount, enterprise is the best (but costs a lot) and gives you 150$ monthly credit, that is enough to run D12V2 VM for 235 hours per month.
  4. With new subscription you get new tenant. Now we need to activate D365 trial on this tenant. That’s a mandatory step for ARM onboarding. Existing customers can follow steps on the customer source  to request access via email. Partners can find details on the partner source , you have 2 options there: request new tenant with trial or activate trial on existing tenant. We will activate trial because we already have a tenant with subscription, but it’s possible to transfer subscription to new tenant as well.
  5. To activate trial on existing tenant
    1. Create new user .AzureActiveDirectoryAddUser.jpg
    2. Make new user Owner of the subscriptionAzureSubscriptionOwner.jpgAzureSubscriptionOwnerNew.jpg
    3. Make new user Global admin of Active Directory.AzureActiveDirectoryUserRole.jpg
    4. Follow a link to trial offer from partner source article. You need to login using credentials of newly created user.ActivateTrial.jpgconfirmtrial
  6. No we are ready to create new LCS project. Go to LCS and login using user created on step 4. LCSNewProject.jpg
  7. Fill all the details required: Version of AX, project name and methodology.LCSNewProjectDetails.jpg
  8. Setup connection to Azure.LCSMicrosoftAzureSettings.jpg
  9. In the organizations list you will see tenants of project users. You can invite users from different tenants to a project and you will see their organization in the list as well.  lcsnewprojectauthorizeCurrent user should be administrator of the tenant to complete authorization.LCSNewProjectAuthorization.jpgLCSNewProjectAuthorizationComplete.jpg
  10. Add Dynamics Deployment Services [wsfed-enabled] to the subscriptionAddDynamicsDeploymentServices.jpg
  11. Setup Azure connector. Check “Configure to use Azure Resource Manager” checkbox or you won’t be able to deploy any VM starting from Update 2. Azure Subscription Id and tenant name could be found on Azure portal.LCSSetupAzureConnector.jpgLCSSetupAzureConnector2.jpgLCSSetupAzureConnector3.jpg
  12. For ARM deployments we don’t need to download any certificate, so just click “Next” on this step.lcssetupazureconnector4
  13. Select Azure region. Please note that not all regions are available for Visual Studio Subscriptions. If you select wrong region you will have to create new connector with another region because all deployments would fail.LCSSetupAzureConnectorRegion.jpg
  14. Deploy new Demo VMLCSDeployNewVM.jpgLCSDeployNewVM2.jpgLCSDeployNewVM3.jpg
  15. Enter VM name and go to Advance settingsLCSDeployNewVM5.jpg
  16. Select demo data package or “None” for blank environment. Here you could select demo data from ISV partners as well if they shared it with you.LCSDeployNewVM6.jpg
  17. Select number of disks. Select 7 if you want to scale it down to D12V2 later, otherwise you would have to manually delete them, that is not an easy task, because it’s not possible to change size if target VM has different disks configuration. LCSDeployNewVM7.jpg
  18. Select GER configuration to be deployed. You can deploy any later from assets library if you missed this step.LCSDeployNewVM8.jpg
  19. Select VM size. Different sizes have different hardware configuration and costs. To find costs you can use Pricing calculator. I prefer to use D13V2 and D12V2 because I think they have best  price–performance ratio.LCSDeployNewVM9.jpg

That’s all. Usually deployment takes up to 5 hours. Don’t forget to setup auto shutdown to save your costs!

Links

Filter OData entity by enum field.

As you may know, logic apps do not have any triggers available for Dynamics365 for Operations. So we have to use recurrence trigger to read data periodically from a data entity and obviously we want to filter a query. This is pretty straightforward with string or integer fields, but not with enums.  Under the hood AX enums are enumeration in OData.

For example, I have new entity “RentalInvoices” and I want to filter it by AXCRMTransferStatus field and select only “pending” records.

Designer view:

LogicAppODataFilterDesignerView.png

Code view:

LogicAppODataFilterCodeView.png

Role-based security in Dynamics 365 for Operations. Export security changes and Security diagnostics tool.

As we know from my previous post we can create security artifacts from Visual Studio and user interface. Now we want to deploy them. All objects created in VS could be deployed via deployable package, there is no difference with any code you created. Changes done from UI could be deployed as data via data package. Out of the box we have three data entity to work with security customizations:

SecurityCustomizationEntities.jpg

In the export file for duty customization we will get duty name and xml object contains all privileges assigned to the duty. Other two (roles and privileges) have similar structure.

ExportedDutyChanges.jpg

ExportedDutyChangesXML.jpg

That’s a big improvement in security setup, because in AX 2012 it was hard to track what changes were done in test environment and should be transferred to live.

Security diagnostics tool

To easy the problem of security setup in AX 2012 we have Security Development Tool, unfortunately, it’s not available in current version (Microsoft is working on the replacement). However, there is another useful tool – Security diagnostics tool.

Each form in AX has “Options” tab on the action pane where you can find “Security diagnostics” button. It shows you a list of all roles, duties and privileges that grant access to current form. Using buttons on the top of the dialog you can add role to specific user, duty to specific role or privilege to specific duty to quickly grant access to current form.

SecurityDiagnosticsFromForm.jpg

Using task recorder to setup security.

Task recorder  has been re-built in current release and could be used in different scenarios apart of actual task recording. One of them is security setup, now you can analyse task recording with Security diagnostics tool.

Create task recording.

taskrecorder

taskrecordersteps

Save it.

taskrecordersavesteps

Go to System administrations -> Security -> Security diagnostics for task recordings and open saved recording.

SecurityDiagnosticsOpenRecording.jpg

As the result you will see all menu items involved. When you select user AX shows if he already has permission to entry points.

SecurityDiagnosticsSelectUser.jpg

“Add reference” button will open you Security diagnostics dialog, exactly the same we saw using Security diagnostics tool, where you can do all the setup.

SecurityDiagnosticsAddtoUsersRole.jpg

Dynamics 365 for Operations. Code to disable XDS policy.

To disable XDS policy in AX 2012 we can use

xdsServices.setXDSState(0);

However, this method does not exist in new AX any more. Now we need to wrap code where we want to disable XDS policy with unchecked(Uncheck::XDS)

unchecked(Uncheck::XDS)
{
    select ValidTimeState(_asOfDate) maxof(ValidTo) from hcmEmployment
        where hcmEmployment.Worker == _workerRecId;
}