Friday, 21 November 2014

Reading Customer from C# AIF Service Ax 2012

static void Main(string[] args)
{
    string customer = "US-004";

    AxdCustomer foundCustomer = null;

    CallContext context = new CallContext();

    context.Company = "USMF";
    // CON_ReadCustomer.Con_ReadCustomerServiceReference.CustomerService proxy = new CON_ReadCustomer.Con_ReadCustomerServiceReference.CustomerService();

    CustomerServiceClient proxy = new CustomerServiceClient();

    try
    {

        foundCustomer = proxy.read(context, Program.readCritera(customer));
        Console.WriteLine("AccountNum : " + foundCustomer.CustTable[0].AccountNum);
        Console.WriteLine("CustGroup : " + foundCustomer.CustTable[0].CustGroup);
        Console.WriteLine("Name : " + foundCustomer.CustTable[0].Name);
        //Console.WriteLine("Name : " + foundCustomer.CustTable[0].Name);
        Console.ReadLine();

    }

    catch (Exception e)
    {
            Console.WriteLine(e.Message);         
    }


    public static EntityKey[] readCritera(string customerAccount)
    {

        AxdEntity_CustTable custTable = new AxdEntity_CustTable();

        EntityKey[] entityKeyList = new EntityKey[1];

        EntityKey key = new EntityKey();

        KeyField[] keyFields = new KeyField[1];

        KeyField keyField = new KeyField();

        keyField.Field = "AccountNum";

        keyField.Value = customerAccount;

        keyFields[0] = keyField;

        key.KeyData = keyFields;

        entityKeyList[0] = key;

        return entityKeyList;
    }

}

No comments:

Post a Comment

Best Practices for Troubleshooting Application Issues in D365 and Power Platform

When facing application issues, it’s important to systematically troubleshoot before reaching out for support.  Follow these steps to ensure...