I got following Error when I called the Read method of Dynamics Ax AIF service.
“Wrong field ID in the key data container in entity key”
My code snippet is as follow and I did not found anything wrong with it.
StudentInfoRef.KeyField keyField = new StudentInfoRef.KeyField() { Field = "FirstName", Value = "Ali2" }; // Create an entity key instance and put in the key field data StudentInfoRef.EntityKey entityKey = new StudentInfoRef.EntityKey(); entityKey.KeyData = new StudentInfoRef.KeyField[1] { keyField }; // Create an array of entity keys and put in the previously StudentInfoRef.EntityKey[] entityKeys = new StudentInfoRef.EntityKey[1] { entityKey }; StudentInfoRef.StudentInfoServiceClient _Client = new StudentInfoRef.StudentInfoServiceClient(); StudentInfoRef.CallContext _callContext = new StudentInfoRef.CallContext(); _callContext.Company = "USSI"; StudentInfoRef.AxdStudentInfo _StudentInfo = _Client.read(_callContext, entityKeys); StudentInfoRef.AxdEntity_StudentInfoTable _StudentInfoTable = _StudentInfo.StudentInfoTable[0];
After trouble shooting I found that I was trying to read on field which have same value in multiple rows. For example I am trying to read from filed FirstName and value “Ali” exists more than one row.
It is recommend that read method will applied on column or field which have unique index.
I was working on testing data, so I delete the all records which have “Ali” value in “FirstName” field. Only one record left for value “Ali”. This time Read method works perfectly right.
It is recommended that if you have repeated values in different rows, you Find method of dynamics Ax 2012.