Wednesday, December 31, 2014

Applying Current User Id range in an AOT query

If you want to apply a range to an AX 2012 AOT query, you can simply add a new range to the field and specify the integer or string value against them. However, if you want to apply a range on a User Id field and want to provide the value of Currently logged in user, you need to get the value dynamically and pass that value to the query. Below snap shot shows a very simple way to achieve this.

Tips on Extensible Data Security in AX 2012

Recently, I had chance to work on Extensible Data Security and noticed few things which can be very helpful, they are posted below.

  1. XDS can hurt performance sometimes if query is not designed well. In order to design security without hurting the performance, always try to reduce number of joins in your Security Policy Query.
  2. If your requirement is complex and needs to add some dynamic filters to the query. In that case you can create a temporary table with type TEMPDB and override its xds() method to fill the table dynamically. This method can be considered for performance improvements as it would reduce query joins. For this, please see xds method on the table MyLegalEntitiesForXDS
  3. If you have to disable XDS, consider following 2 methods
    1. Create a view and fetch data from that view. View is a different object for XDS framework, thus the security applied on the table will not be considered for view and you will see the data.
    2. Second method to disable the security is mentioned here in my other post.

AX 2012 Disable/ByPass extensible data security (XDS) through code

Extensible Data Security or XDS is a framework introduced in AX 2012 to apply security on data. We had RLS or Record Level Security in AX 2009. However, XDS is completely a new framework with more capabilities in order to apply data security. This post is about disabling or bypassing the XDS using code. For more details about XDS, download a whitepaper provided by Microsoft using following link.

Disabling/Bypassing XDS or Extensible Data Security:
Recently, I had a requirement to restrict users from viewing all the Warehouses available and they must be able to see only the Warehouses they belong to. I designed a new security policy and it started working very easily without much problem. However, the problem was on Inventory Transfer From where we have two fields for Warehouses:
  1. From warehouse and
  2. To warehouse
Our requirement was to restrict only From warehouse and To warehouse MUST show all the warehouses available so they can issue inventory to any warehouse but should not be allowed to issue inventory from the warehouse they don't belong to. In order to achieve this, I had to disable the XDS on To Warehouse lookup method. I did override the lookup() method on To Warehouse field on the datasource and below is the code which I wrote to disable the XDS.

public void lookup(FormControl _formControl, str _filterStr)
    XDSServices                      xXDS = new XDSServices();

    xXDS.setXDSState(0); // Disable XDS
    super(_formControl, _filterStr);
    xXDS.setXDSState(1); // Enable XDS

Wednesday, December 17, 2014

AX 2012 showing lookup from different (cross) company

I had a requirement in AX 2012 in which I had to show Customer Lookup from a different company. Our requirement was to provide user with two lookups on the Vendor Form (VendTable).

  1. One lookup - To select the company from which they want to see Customers
  2. Second lookup - Show Customers from the company selected on above lookup
To achieve this I added 2 fields in the table VendTable
  1. TargetCompanyId (EDT: SelectableDataAreaId)
  2. TargetCustAccount (EDT: CustVendAC) - Don't use CustAccount EDT, I tried this in AX2009 and it appeared to be using EDT relation and could not work.
After adding these fields, create a new relationship and add both of the above added fields in this relationship.

Drop the fields on the form and you will see Customer will appear from the company you have selected in the first lookup. Change company from the first lookup and see how data in the customer lookup changes.

Sunday, December 14, 2014

Calling Events of AX Form's Datasource

While working on AX 2012 Forms, we need to call form's datasource events every now and then from other events. Below is the example that shows how you can call any event like modified, validate etc. of a form's datasource from any other method.

Below example shows how you can call modified method of ItemId field under InventJournalTrans datasource.

FormDataObject          itemIdField;
itemIdField = inventjournalTrans_ds.object(fieldnum(InventJournalTrans, ItemId));

Monday, November 24, 2014

Installing Sharepoint 2010 foundation on Windows 7

While trying to Install Sharepoint 2010 on Windows 7 to setup Enterprise Portal, I was getting an error that Windows Server 2008 R2 is needed. I was able to install after adding following setting to the file in the setup directory.


Open the above mentioned file and add the following line to it.

<Setting Id="AllowWindowsClientInstall" Value="True"/>

After adding this line, the file would like something like that.

<Package Id="sts">

        <DATADIR Value="%CommonProgramFiles%\Microsoft Shared\Web Server Extensions\14\Data"/>

<Logging Type="verbose" Path="%temp%" Template="Microsoft SharePoint Foundation 2010 Setup *.log"/>
<Setting Id="UsingUIInstallMode" Value="1"/>
<Setting Id="SETUP_REBOOT" Value="Never" />
<Setting Id="AllowWindowsClientInstall" Value="True"/>

Once you add this line, run the setup again and you should be good to go.