Home > Dynamics Ax > Dynamics Ax – AIF – Axd Read Action with single entity key have multiple Key Fields

Dynamics Ax – AIF – Axd Read Action with single entity key have multiple Key Fields


Read Action with single entity key, have multiple key Fields:

While working on integration application, I had come across the situation, where table is having unique index with 6 fields.

i.e. Entity key for this table is defined on these 6 fields. To get the outbound information from this corresponding Axd class (to invoke the Read action on this related Axd we have to pass the 6 keyfields as entity key)

 

Here the sample code for calling Read on the corresponding Axd class.

C# Code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.ServiceModel;

using TestWebApplLognElements.HndWebApplLoginElements;

 

 

namespace TestWebApplLognElements

{

    class Program

    {

        static void Main(string[] args)

        {

            HndHNDWebApplLogElmntsServiceClient proxy = new HndHNDWebApplLogElmntsServiceClient();

            AxdHNDWebApplLoginElements axd = new AxdHNDWebApplLoginElements();

 

            TestWebApplLognElements.HndWebApplLoginElements.EntityKey[] entityKeyList;

 

           

            TestWebApplLognElements.HndWebApplLoginElements.EntityKey entityKey = new TestWebApplLognElements.HndWebApplLoginElements.EntityKey();

            TestWebApplLognElements.HndWebApplLoginElements.KeyField[] keyField = new TestWebApplLognElements.HndWebApplLoginElements.KeyField[6];

 

            //keyField[0].Field = "LoginId";

            //keyField[0].Value = "";

            //Error if we use the above commented lines: Object reference not set to an instance of an object.

            //Intially i tried above way, but it is giving above error so it’s better to pass the values as below.           

 

KeyField myKeyField = new KeyField();

            myKeyField.Field = "LoginId";

            myKeyField.Value = "";

            keyField[0] = myKeyField;

 

 

            KeyField myKeyField1 = new KeyField();

            myKeyField1.Field = "WebGroup";

            myKeyField1.Value = "";

            keyField[1] = myKeyField1;

 

 

            KeyField myKeyField2 = new KeyField();

            myKeyField2.Field = "TableGroupAll";

            myKeyField2.Value = "All";

            keyField[2] = myKeyField2;

 

            KeyField myKeyField3 = new KeyField();           

            myKeyField3.Field = "ElementItem";

            myKeyField3.Value = AxdExtType_HNDWebApplElementItem.LawyerClient.ToString();

            keyField[3] = myKeyField3;

 

 

            KeyField myKeyField4 = new KeyField();

            myKeyField4.Field = "CompanyId";

            myKeyField4.Value = "";

            keyField[4] = myKeyField4;

 

            KeyField myKeyField5 = new KeyField();

            myKeyField5.Field = "CompanyAll";

            myKeyField5.Value = "All";

            keyField[5] = myKeyField5;

 

     

            EntityKey myEntityKey = new EntityKey();

            myEntityKey.KeyData = new TestWebApplLognElements.HndWebApplLoginElements.KeyField[6] { keyField[2], keyField[1], keyField[0], keyField[5], keyField[4], keyField[3] };

            entityKey = myEntityKey;

 

 

            entityKeyList = new TestWebApplLognElements.HndWebApplLoginElements.EntityKey[1] { entityKey };

 

            axd = proxy.read(entityKeyList);

            Console.Write(axd.HNDWebApplLogElmnts[0].AccessRights);

            Console.ReadLine();

 

 

        }

    }

}

……………. Red rose

Advertisements
Categories: Dynamics Ax
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: