Skip to main content

Create AxTableContext from IAxaptaRecordAdapter or from a RecId

Somtimes we need to create a record context from a custom record but not based on a record from a data set. It is a bit tricky to create a menu item record context fram an IAxaptaRecordAdapter or a RecId.

Here is an example


// Get the recid for which record the context should be fore
// where record is any record from any given table in Ax
Int64 recId = record.GetField("RecId”);                    

int tableId = TableMetadata.TableNum(this.AxSession, "[TABLENAME]"); 

// Create a dict table
Proxy.DictTable dictTable = new Proxy.DictTable(AxSession.AxaptaAdapter, tableId);

// Get the field id
int fieldId_RecId = TableDataFieldMetadata.FieldNum(this.AxSession, dictTable.name(), "RecId");

// Create the table metadata
TableMetadata tblMetadata = MetadataCache.GetTableMetadata(AxSession, tableId);

// Create the dictinary object
Dictionary<int, object> dictRecId = new Dictionary<int, object>();
dictRecId.Add(fieldId_RecId, recId);

// Create the tablekey
AxTableDataKey tableKey = AxTableDataKey.Create(tblMetadata, dictRecId, null);

// Finally create the context and add it to tne menu item
AxTableContext context = AxTableContext.Create(tableKey);
AxUrlMenuItem menuItem = new AxUrlMenuItem("[NAME_URL_MENU_ITEM] ");
menuItem.MenuItemContext = context;

Comments

Popular posts from this blog

Dynamics 365 for operations – Table extensions

Background Extensions are a new way to add functionality and custom code to the D365 system without changing the standard code. In fact, Microsoft has announced that edit standard elements like those that we have done in the past will not be possible after 2017. By using extensions, we can achieve the same result by simply extending the standard system => EXTENSIONS. To read more about the difference between overlaying and extensions follow this link https://ax.help.dynamics.com/en/wiki/customization-overlayering-and-extensions/#extensions Extending tables By using table extensions, we can create a new table that adds new fields, field groups, indexes, mappings, relations, methods, subscribe to event handlers and more. When extending tables we need to follow the naming rule as such: <TABLENAME><_Extension> the compiler understands the _Extensions suffix and knows that the table in question is extending a table from the standard system. This gives us access ...

Plug-able Authentication in Microsoft Dynamics AX 2012

I have worked in many projects involving the Enterprise Portal for Ax ranging from version 2.5. One of the biggest issue for the end customer/user has been the ability to have a plug-able authentication for EP. This has been an issue for example for customers that have other portals based on Share Point as well as custom build ASP.NET web sites. All these portals are able to share the authentication with Single Sign On, SSO. But until now with version 2012 of Ax this has not been possible since earlier versions of Ax have only supported Windows Authentication. So in scenarios where you implement an EP site for a customer that has other portals and uses for example forms authentication, if you are not running Ax 2012 you have to have a special/dedicated log-on to EP. One of the biggest advantages is the fact that now external users do not have to be in Active Directory mixed up with all the internal users or located in an extra AD repository with all the administrative IT work l...

Using the Dynamics Ax Office Add-in

Hi everyone, I have been playing around with some Ax 2012 stuff and I was testing the Office Add-in and I think it is preatty cool. In order to use the Office Add-in it has to be installed with the Ax client and some settings needs to be made in the system as well. Lets dive into how it can be done, this is how I tested this function and it can most certainly be done in different ways. First I created a small query called MyCustTableQuery Next step is to provide information about the query and expose it so we can use the query in our office application, my application of choice was Excel. In Dynamics Ax 2012 go to Organization Administration> Setup> Document Management > Document datasources Here it is possible to select a query or service, in my example I used the query. So here i added a new record of data source type Query and then I selected my newly created MyCustTableQuery . Now the query is ready to use in what ever office application we ha...