Data
The Enterprise Portal ASP.NET controls access and manipulate data through data binding to AxDataSource. You can also access the data through the APIs directly. The Microsoft.Dynamics.Framework.Data.Ax namespace contains several classes that work together to retrieve data.
For example, use the following code to get the current row from the DataSetView.
private DataSetViewRow CurrentRow
{
get
{
try
{
DataSetView dsv = this.ContactInfoDS.GetDataSet().DataSetViews[this.
ContactInfoGrid.DataMember];
return (dsv == null) ? null : dsv.GetCurrent();
}
// CurrentRow on the dataset throws exception in empty data scenarios
catch (System.Exception)
{
return null;
}
}
}
|
To set the menu item with the current records context, use the following code.
...
...
DataSetViewRow currentContact = this.dsEPVendTableInfo.GetDataSourceView(gridConatcts.
DataMember).DataSetView.
GetCurrent();
using (IAxaptaRecordAdapter contactPersonRecord = currentContact.GetRecord())
{
((AxUrlMenuItem)e.MenuItem).MenuItemContext = AxTableContext.Create(AxTableDataKey.
Create(this.BaseWebpart.Session, contactPersonRecord, null));
}
|
Metadata
The Enterprise Portal framework provides a rich set of APIs to access the metadata from the AOT in managed code. The Microsoft.Dynamics.Framework.Metadata.Ax
namespace contains several classes that work together to retrieve
metadata from the AOT. Enterprise Portal controls use the metadata for
retrieving formatting, validation, security, and other information from
the AOT and apply it on the Web user interface automatically. Developers
can also use these APIs to retrieve the metadata in their user
interface logic.
MetadataCache is the main entry point to accessing metadata and provides static methods. For example, to get the EnumMetadata, you use MetadataCache.GetEnumMetadata, as shown here.
/// <summary>
/// Loads the dropdown with the Enum values.
/// </summary>
private void LoadDropdownList()
{
EnumMetadata salesUpdateEnum = MetadataCache.GetEnumMetadata(this.AxSession,
EnumMetadata.EnumNum(this.AxSession, "SalesUpdate"));
foreach (EnumEntryMetadata entry in salesUpdateEnum.EnumEntries)
{
ddlSelectionUpdate.Items.Add(new ListItem(entry.GetLabel(this.AxSession), entry.
Value.ToString()));
}
}
|
To get the label value for a table field, use the following code.
...
...
TableMetadata tableSalesQuotationBasketLine = MetadataCache.GetTableMetadata(
this.AxSession, "CustTable");
TableFieldMetadata fieldItemMetadata = tableSalesQuotationBasketLine.FindDataField-
("AccountNum");
String s = fieldItemMetadata.GetLabel(this.AxSession);
...
...
|
Figure 1 shows some key object access hierarchy for metadata. Not all APIs are included in this figure.