Creating an AxTableContext from a RecId

From the category "basic but must use", another code snippet of how you would create an AxTableContext in an EP page starting from a  RecId value, in order to pass it to another page. Remember, lots of ways to do this, so, pick your favorite.

Small note: here we are only using the first field in the PrimaryIndex. I am basically using SurrogateKey on my tables, so of course this will work. If you know your tables to be using other PKs with multiple columns, change it.

    private void NavigateToARecord(string RecIdFieldName)
        TableMetadata tm = MetadataCache.GetTableMetadata("YourTable");
        int tableId = tm.Id;
        int fieldId = tm.PrimaryIndex.Fields[0].FieldId;
        long wKeyRecID = 0;

        if (this.CurrentRow != null) // here you should have the definition for the CurrentRow custom property
            wKeyRecID = (long)this.CurrentRow[RecIdFieldName];

        AxUrlMenuItem url = new AxUrlMenuItem("YourURLMenuItemName");
        url.MenuItemContext = AxTableContext.Create((IAxTableRowKey)AxTableDataKey.Create(tableId, string.Format("[{0}:{1}]", fieldId, wKeyRecID)));
        DialogHelper.Navigate(url, this);

No comments:

Post a Comment