Quantcast
Channel: AX Developer Forum
Viewing all articles
Browse latest Browse all 9880

Creating a Customer with a DirPartyPostalAddressView - AX Integration

$
0
0

Hello,

I am trying to create a new Customer (Person) with an Address. My Code is the following:

                CustomerServiceClient proxy = new CustomerServiceClient();
                CallContext context = new CallContext();
                context.Company = "MTR";

                AxdCustomer customer = new AxdCustomer();
                AxdEntity_CustTable custTable = new AxdEntity_CustTable();

                custTable.AccountNum = "CUST-000011";
                custTable.Currency = "USD";
                custTable.CustGroup = "20";
               custTable.OneTimeCustomer = AxdExtType_OneTimeCustomer.Yes;
                custTable.OneTimeCustomerSpecified = true;

                //Create the party record
                AxdEntity_DirParty_DirPerson party = new AxdEntity_DirParty_DirPerson();
                party.NameAlias = "Becky";

                //Set the name fields
                AxdEntity_PersonName personName = new AxdEntity_PersonName();
                personName.FirstName = "Becky";
                personName.MiddleName = "ILiveForThis";
                personName.LastName = "Newell";

 

                //Add the names to the party record and set the name sequence
                party.PersonName = new AxdEntity_PersonName[1] { personName };
                party.NameSequence = "FirstLast";

                //Create a postal address
                AxdEntity_DirPartyPostalAddressView address = new AxdEntity_DirPartyPostalAddressView();
                address.LocationName = "Location Name";
                address.Street = "111 NE 5th St";
                address.City = "Beverly Hills";
                address.State = "CA";
                address.CountryRegionId = "USA";
               address.ZipCode = "90210";
               address.Roles = "Home;Delivery";

                AxdExtType_EffectiveDateTime myDateTime = new AxdExtType_EffectiveDateTime();
               myDateTime.localDateTime = Convert.ToDateTime("11/8/2013");
               myDateTime.localDateTimeSpecified = true;
               myDateTime.timezone = AxdEnum_Timezone.GMTMINUS0600CENTRALTIME;        
               myDateTime.timezoneSpecified = true;

               address.ValidFrom = myDateTime;

                AxdExtType_ExpirationDateTime expireDateTime = new AxdExtType_ExpirationDateTime();
                expireDateTime.localDateTime = Convert.ToDateTime("12/20/2020");
                expireDateTime.localDateTimeSpecified = true;
                expireDateTime.timezone = AxdEnum_Timezone.GMTMINUS0600CENTRALTIME;
                expireDateTime.timezoneSpecified = true;
                address.ValidTo = expireDateTime;

                //Create an email address
               AxdEntity_DirPartyContactInfoView email = new AxdEntity_DirPartyContactInfoView();
               email.LocationName = "Prospect Email";
               email.Type = AxdEnum_LogisticsElectronicAddressMethodType.Email;
               email.TypeSpecified = true;
               email.Locator = "whatever@hotmail.com";
               email.Roles = "Home";

                //Create a phone number
               AxdEntity_DirPartyContactInfoView cellPhone = new AxdEntity_DirPartyContactInfoView();
               cellPhone.LocationName = "Cell phone";
               cellPhone.Type = AxdEnum_LogisticsElectronicAddressMethodType.Phone;
               cellPhone.TypeSpecified = true;
               cellPhone.Locator = "555-234-2234";
               cellPhone.Roles = "Home";

                //Add the addresses to the party record and the party to the CustTable record
               custTable.DirParty = new AxdEntity_DirParty_DirPartyTable[1] { party };
               custTable.DirParty[0].DirPartyPostalAddressView = new AxdEntity_DirPartyPostalAddressView[1] { address };
               custTable.DirParty[0].DirPartyContactInfoView = new AxdEntity_DirPartyContactInfoView[2] { email, cellPhone };

                //Add the CustTable record to the Customer entity
               customer.CustTable = new AxdEntity_CustTable[1] { custTable };

                //Create the customer
               proxy.create(context, customer);

If I comment  this 2 lines:

custTable.DirParty[0].DirPartyPostalAddressView = new AxdEntity_DirPartyPostalAddressView[1] { address };

custTable.DirParty[0].DirPartyContactInfoView = new AxdEntity_DirPartyContactInfoView[2] { email, cellPhone };

the creation is normal, if i use them back, a "generic " error is thrown while creating the customer:

{System.ServiceModel.FaultException`1[WebApplication1.CustomService.AifFault]:
Request Failed. See the Exception Log for details.
(Fault Detail is equal to WebApplication1.CustomService.AifFault).}

Please advise...

Thank you

 


Viewing all articles
Browse latest Browse all 9880

Trending Articles