Sunday, September 16, 2018

Add State Values for a Customer Address in Web Services using .NET

This is a sample code in .NET on how to set the Address State values in an Entity/Customer record using Webservices.

 

Customer cust = new Customer();

cust.companyName = "John Doe";

 

CustomerAddressbook custAddBook = new CustomerAddressbook();

custAddBook.addr1 = " 123 Main St";

custAddBook.city = "San Mateo";

custAddBook.state = "CA";

 

CustomerAddressbook[] custAddressBook = new CustomerAddressbook[1];

custAddressBook[0] = custAddBook;

 

CustomerAddressbookList custAddBookList = new CustomerAddressbookList();

custAddBookList.addressbook = custAddressBook;

cust.addressbookList = custAddBookList;

_service.add(cust);

 

 

Here is the Equivalent SOAP request:

 

 <Envelope>
<Header>
     <preferences>
     <useConditionalDefaultsOnAdd>true</useConditionalDefaultsOnAdd>
     <ignoreReadOnlyFields>true</ignoreReadOnlyFields>
     </preferences>
</Header>
<Body>
     <add>
          <record type="Customer">
          <companyName>John Doe</companyName>
          <addressbookList>
               <addressbook>
               <addr1>123 Main St</addr1>
               <city>San Mateo</city>
               <state>CA</state>
               </addressbook>
          </addressbookList>
          </record>
     </add>
</Body>
</Envelope>

 

 

Note: State value is not defined in the schema and less-restrictive. However, if users assign an invalid Country value in the address, this will generate an error. The list of State/Country can be located at : Setup > Company > States/Provinces/Counties

No comments:

Post a Comment