Other Languages - How to retrieve customer with CustNumber in Microsoft Dynamics Axapta

Asked By Gopal Kumar on 22-Dec-11 11:29 AM
Hi all

I was trying to use below function to retrieve a particular customer using Account number...how to add where clause as below is failing.

public string ReadCustomerByNumber(String CustomerNumber)
        { 
            // Create the .NET Business Connector objects.
            Axapta ax;
            AxaptaRecord axRecord;
            string tableName = "CustTable";

            // The output variables for calls to the 
            // AxRecord.get_Field method.
            object  fieldStateId; 


            try
            {
                // Login to Microsoft Dynamics AX.
                ax = new Axapta();
                System.Net.NetworkCredential nc = new System.Net.NetworkCredential("ABC", "XYZ");
                ax.LogonAs("AXBCASAdmin", "GBABG", nc, "411", string.Empty, string.Empty, string.Empty);


                // Create a query using the AxaptaRecord class
                // for the StateAddress table.
                using (axRecord = ax.CreateAxaptaRecord(tableName))
                {

                    // Execute the query on the table.
                    axRecord.ExecuteStmt("select Name from %1 where %1.AccountNumber == '" + CustomerNumber + "'");              
                    // Create output with a title and column headings
                    // for the returned records.
                    //Console.WriteLine("List of selected records from {0}",
                    //    tableName);
                    //Console.WriteLine("{0}\t{1}", strNameField, strStateIdField);


                    // Loop through the set of retrieved records.
                    while (axRecord.Found)
                    {
                        // Retrieve the record data for the specified fields.
                        //fieldName = axRecord.get_Field("AccountNum");
                        fieldStateId = axRecord.get_Field("Name");

                        // Display the retrieved data.
                        //Console.WriteLine(fieldName + "\t" + fieldStateId);

                        // Advance to the next row.
                        axRecord.Next();
                    }


                    // Keep the console window open.
                    //System.Console.WriteLine("Press any key to exit.")
                    //System.Console.ReadKey();        
                    
                }
                
            }
            catch (Exception e)
            {
                //Console.WriteLine("Error encountered: {0}", e.Message);
                // Take other error action as needed.
            }
            return "test";
        }

Thanks in advance
MOhan
Tom Ramirez replied to Gopal Kumar on 22-Dec-11 11:32 AM
Please give more info. Thanks.
Gopal Kumar replied to Tom Ramirez on 22-Dec-11 11:41 AM
Thanks for your reply..

I was trying to pass a customer AccountNum and have to read RecId for that customer.

but getting below error

Microsoft.Dynamics.BusinessConnectorNet.BusinessConnectorException: Unable to compile "static void ComExecuteStmt(CustTable axTbl_0) { select Name from axTbl_0 where axTbl_0.AccountNumber == '65C00080';} ".
   at Microsoft.Dynamics.BusinessConnectorNet.Axapta.ExecuteStmt(String statement, AxaptaRecord[] paramList)
   at Microsoft.Dynamics.BusinessConnectorNet.Axapta.ExecuteStmt(String statement, AxaptaRecord param1)
   at Microsoft.Dynamics.BusinessConnectorNet.AxaptaRecord.ExecuteStmt(String statement)
   at KumonDataIntegration.CustomerServiceHelper.ReadCustomerByNumber(String CustomerNumber) 

let me know if you need any other info.

Regards