Retrieve the RecId value from the AxQueryString

Retrieving the RecId value from the AxQueryString of your current page is fairly simple; this value of course is allowing you to select the record that was passed as a reference to your page (either the record that was selected in a grid and you are opening it in a details page, or a childs page that you will filter based in the parent's RecId just passed).


The code can be found in a number of standard pages, but I'm using my codebook as an easier reference:
 
            int     tableId = 0;
            Int64   recId = 0;

            if (this.AxQueryString != null && this.AxQueryString.RecordContext != null)
            {
                tableId = this.AxQueryString.RecordContext.TableId;

                IEnumerator<KeyValuePair<int, object>> en = this.AxQueryString.RecordContext.DataKey.GetEnumerator();

                int fieldId = this.AxQueryString.RecordContext.DataKey.Table.Fields.GetByName("RecId").FieldId;
                while (en.MoveNext())
                {
                    if (en.Current.Key == fieldId)
                    {
                        recId = Convert.ToInt64(en.Current.Value);
                        break;
                    }
                }
            }

Just a reminder, doing the following will better depict the context:

            AxInfologCtrl.Current.ShowInfo(this.AxQueryString.WKEY.ToString());
            AxInfologCtrl.Current.ShowInfo(this.AxQueryString.WREC.ToString());
            AxInfologCtrl.Current.ShowInfo(recId.ToString());


and will output:

            [65534:5637152826]            0            5637152826

No comments:

Post a Comment