C Customer Account Transaction

From Sage Evolution SDK | Documentation Portal
Revision as of 11:03, 23 October 2015 by Admin (Talk | contribs)

Jump to: navigation, search

The Customer class is used to create Customer Accounts which can be used on Customer related processes. The following code displays how a new Customer is created with the basic necessary properties like Code and description specified.

            //Assign variable C to Customer class
            Customer C = new Customer();
            //Specify Customer properties
            C.Code = "CustomerSDK1";
            C.Description = "supplierSDK1";
            //Use the save method to Save the Customer
            C.Save();

The same Customer can be edited and saved again with updated information like addresses and telephone number. For Delivery Addresses it is necessary to save the Customer first. the following example checks if the customer exists and if the delivery code exists.

            string DC = "Del2";
            string Cust = "CustomerSDK1";
 
            //check if Customer exists note to capture a delivery address the Customer must exist first
            if (Customer.FindByCode(Cust) == -1)
            {
                Customer NewCust = new Customer();
                //NewCust.Description = Cust;
                NewCust.Description = Cust;
                NewCust.Save();
            }
            Customer C = new Customer(Cust);
            //Set new properties
            C.Telephone = "113456";
            C.EmailAddress = "Customer@SDK";
            //Set Postal or physical address
            C.PostalAddress = new Address("Postal Address 1", "Post 2", "Post 3", "Post 4", "Post 5", "PC");
            C.PhysicalAddress = new Address()
            {
                Line1 = "Physical1",
                Line2 = "Physical2",
                Line3 = "Physical3",
                Line4 = "Physical4",
                Line5 = "Physical5",
                PostalCode = "2000",
            };
            //Check for Delivery Address code if false save
            if (DeliveryAddressCode.FindByCode(DC) == -1)
            {
                DeliveryAddressCode delAdd = new DeliveryAddressCode();
                delAdd.Code = DC;
                delAdd.Description = ("Delivery address");
                delAdd.Save();
            }
            //Specify the DeliveryAddress address for the code
            Address address = new Address("102 Delivery Address", "Delivery Address 2", "2620");
            C.DeliveryAddresses.Add(DC, address);
 
            //Use the save method to Save the Customer
            C.Save();