Session Object [AX 2012]

Updated: March 29, 2011

Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

When adding code to User Controls for Enterprise Portal, many of the methods that you will use in the Enterprise Portal framework require access to the Session object.

The Session object can be accessed through the web part that is hosting the User Control. The following using statement is required to access the object.

using Microsoft.Dynamics.Framework.BusinessConnector.Session;

A helper method is typically used to make accessing the Session object simple. The following private method can be added to the code for a User Control to provide access to the Session object.

private ISession AxSession
{
    get
    {
        AxBaseWebPart webpart = AxBaseWebPart.GetWebpart(this);
        return webpart == null ? null : webpart.Session;
    }
}

To access the Session object by using the helper method in the previous example, just access the AxSession property defined by the private method. The following example shows how the Session object is used when metadata for a table is retrieved.

int custTableNum;
custTableNum = TableMetadata.TableNum(this.AxSession, "CustTable");

Community Additions

ADD
Show: