Session Object

Dynamics AX 2009

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: