Wednesday, October 24, 2018

How to set values to specific fields that need boolean specification in C#/.NET

Some fields when coding in C# have a corresponding boolean specification. An example is country on the addressBook sublist. When this is not set, the value that will be set to the main field will not be included on the SOAP Request. Please note that this is a limitation in C# and not with NetSuite. Here's a sample code in C# to set the country and countrySpecified fields.

/*******************************************
*The Web Service example below performs an Add or
*Update request for a Customer record to set Country
*parameter other than US
*/

CustomerAddressbook address = new CustomerAddressbook(); address.defaultBilling = true; 
address.defaultBillingSpecified = true; 
address.label = "Billing Address"; 
address.addr1 = "4765 Sunset Blvd"; 
address.city = "Beverly Hills"; 
address.state = "ON"; 
address.zip = "L3R 3W5"; 
address.country = Country._canada; 
address.countrySpecified = true; // need to set 'Country Specified' to true. 

Check the SOAP request (Go to Setup > Integration > Web Services Usage Log). Notice that the country field has a value in the SOAP request:

<q1:addressbookList>
<q1:addressbook>
<q1:defaultBilling>true</q1:defaultBilling>
<q1:label>Billing Address</q1:label>
<q1:addr1>4765 Sunset Blvd</q1:addr1>
<q1:city>Beverly Hills</q1:city>
<q1:zip>L3R 3W5</q1:zip>
<q1:country>_canada</q1:country>
<q1:state>ON</q1:state>
</q1:addressbook>
</q1:addressbookList>


 

No comments:

Post a Comment