Search This Blog

Friday, March 9, 2012

Ax2012 Get Table Field Names , Labels using MetaDataService


Before writing this code please take the reference of the service
net.tcp://localhost:8101/DynamicsAx/Services/MetadataService

I have create the windows project with two textboxes,txtTableName,txtFieldsList in the form.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Krishh_GetTableFieldLabels.MetadataServiceReference;

namespace Krishh_GetTableFieldLabels
{
    public partial class GetTableFieldswithLabels : Form
    {
        public GetTableFieldswithLabels()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            AxMetadataServiceClient client = new AxMetadataServiceClient();
            try
            {
                string[] tablenames = new string[1];
                tablenames[0] = txtTableName.Text;

                // Gets the table metadata.
                TableMetadata[] tableMetadata = client.GetTableMetadataByName(tablenames);
                TableMetadata tableMetadata1 = tableMetadata[0];

                foreach (DataFieldMetadata fieldMetadata in tableMetadata1.Fields)
                {
                    txtFieldsList.Text += fieldMetadata.Name + "," + client.GetLabelMetadataForLanguageById("EN-US", new string[] { fieldMetadata.LabelId })[0].LabelString + Environment.NewLine;
                }
             
                client.Close();
            }
            catch
            {
                client.Abort();
                throw;
            }
        }
    }
}



4 comments:

  1. Hi, was hoping to implement this but I can't find the metadata service you reference? It is not in my ax 2012 list of services. Can you tell me where you found this service? Thanks

    ReplyDelete
    Replies
    1. Hi
      If it's not deployed...go to AOT and select servicegroups and select system services,right click and deploy the servicegroup, it will deploy all the system services.

      Delete
  2. Hi,
    The system services are hosted by the Application Object Server (AOS) by default, although they can be configured to be hosted in IIS. The system services are automatically installed as part of the setup process and are always available.

    I hope your service was not deployed.

    See in Service and application framework may be metadataservice was not active.

    ReplyDelete
  3. "System Services" does not exist under "Service Groups"...

    So, does not work. Import routes (other article) does not work either. Method is missing there...

    Not very helpful.

    ReplyDelete

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.