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

Calculate ledger balance by dimension set in X++ in AX2012/Dynamics 365 FO

There are a variety of ways users can view balances in the general ledger. Some of the most common options are: 1. Trial balance 2. Financia...