ax 2009 integraton read method

Hi Everyone,

I have created Asp.net web service application project in visual studio2008 .it sucessfully created in ax 2009 table purchTable and form, but how to write read method ,can u help on this,i wrote created method in in this project like below;

public string CreatePurchaseOrder(String purchId, String purchName, String orderAccount, String invoiceAccount, String email, String currencyCode)

{

try

{

ax = new Axapta();

ax.Logon(“CEU”, “en-us”, “”, “”);

AxaptaRecord axrecord;

string tableName = “PurchTable”;

using (axrecord = ax.CreateAxaptaRecord(tableName))

{

axrecord.InitValue();

axrecord.set_Field(“PurchId”, purchId);

axrecord.set_Field(“PurchName”, purchName);

axrecord.set_Field(“OrderAccount”, orderAccount);

axrecord.set_Field(“InvoiceAccount”, invoiceAccount);

axrecord.set_Field(“Email”, email);

axrecord.set_Field(“CurrencyCode”, currencyCode);

axrecord.Insert();

}

}

catch(Exception e)

{

Console.WriteLine(“Error encountered :{0}” , e.Message);

}

return “CreatePurchOrder”;

}

}

}

thanks advance

Find example in How to: Read Data Using .NET Business Connector on MSDN.

Consider using AIF document services instead of directly dealing with tables via Business Connector.

Hi Martin ,

thanks for the reply , i am already tried that one ,but i didn’t get any output,but it will giving message my return message

please find the blow code

public string ReadPurchaseOrder()

{

Axapta ax;

AxaptaRecord axRecord;

String tablename = “PurchTable”;

String purchId = “PurchId”;

String purchName = “PurchName”;

String orderAccount = “OrderAccount”;

String invoiceAccount = “InvoiceAccount”;

String email = “Email”;

Object fieldPurchId, fieldPurchName, fieldOrderAccount, fieldInvoiceAccount, fieldEmail;

try

{

ax = new Axapta();

ax.Logon(“CEU”, “en-us”, “”, “”);

using (axRecord = ax.CreateAxaptaRecord(tablename))

{

axRecord.ExecuteStmt(“select * from %1”);

Console.WriteLine(“list of selected record from:{0}”, tablename);

Console.WriteLine("{0}\t{1}", purchId, purchName, orderAccount, invoiceAccount, email);

while (axRecord.Found)

{

fieldPurchId = axRecord.get_Field(purchId);

fieldPurchName = axRecord.get_Field(purchName);

fieldOrderAccount = axRecord.get_Field(orderAccount);

fieldInvoiceAccount = axRecord.get_Field(invoiceAccount);

fieldEmail = axRecord.get_Field(email);

Console.WriteLine(fieldPurchId + “\t” + fieldPurchName + “\t” + fieldOrderAccount + “\t” + fieldInvoiceAccount + “\t” + fieldEmail);

axRecord.Next();

}

}

}

catch (Exception e)

{

Console.WriteLine(“Error encounterd :{0}”, e.Message);

}

return “readdata”;

}

}

}

but it will not giving outpppput

What do you mean by “it will giving message my return message”? If you get an exception, what’s the error message?

it means what ever i mentioned return value ,it will be displayed that one

but i need to display purchase order values

Unfortunately there is no magic that would return what you want - you’ll have to write code to do it.

But previously i wrote code on create method mentioned on above first message, but it will displays values in ax 2009 purchTable, ,how can i display values in running of service when i wrote read method,can u explain

If I understand what you’re saying, you already know how to return a value, you just want to return a different value. So do it! Construct the return value you want and return it.

You’ll probably want to use a data contract class instead of a simple string.

You would get a data contract automatically if you used a document service.

Hi Martin,

Actually i need to display values from purchTable in above i mentioned service url,in that url when i click the invoke button i need to display values

Yes, I know. What’s the problem? You already know how to return data from your service - it’s what you showed in the third picture. It seems that you know hot to read data through Business Connector. I told you about data contract classes.

Therefore you should build a data contract class, create its instance in ReadPurchaseOrder(), fill its properties with data obtained via Business Connector and return the instance.

Read the documentation to learn more about data contracts.

Hi Martin ,

same read method i wrote in console application it display values,but in this project didn’t displayed,can u tell me the one example and also i searched in google didn’t showing any document.

thanks advance