Sunday, September 16, 2018

Pass a null value to a field via Web Services using C#

Sample .NET C# code to pass on a null value to a field.

Note: This article requires existing knowledge of Web Services and C#.

Instead of using NullField, this sample will pass on the String array into the NullFieldList object.

     // This updates a customer record
     Customer customer = new Customer();

      // Update values
     customer.internalId ="84";
     customer.companyName = "XYZ 2, Inc.";
     customer.email = "bsanders@xyz.com";
     customer.fax = "402-999-9999";

     // Pass on a null value into field name - "PHONE"
     string[] nullfield_phone = new string[] { "phone" }; // Field to nullify value
     customer.nullFieldList = nullfield_phone;  // Invoke field list

     // Invoke update() operation
     WriteResponse response = _service.update(customer);

     // Process the response
     if (response.status.isSuccess)
     {
          Console.Write(
          "\nThe following customer was updated successfully:" +
          "\nkey=" + ((RecordRef)response.baseRef).internalId +
          "\nentityId=" + customer.entityId +
          "\ncompanyName=" + customer.companyName +
          "\nemail=" + customer.email) ;
     }
     else
     {
          Console.Write("ERROR : unable to update" + response.status);
     }

     Console.Read();  // To read on Console

 

 

The above code would generate the following SOAP request

 

SOAP request:

<soap:Envelope>
<soap:Body>
  <update xmlns="urn:messages_2009_2.platform.webservices.netsuite.com">
   <record internalId="84" xsitype="q1:Customer" xmlns:q1="urn:relationships_2009_2.lists.webservices.netsuite.com">
     <nullFieldList xmlns="urn:core_2009_2.platform.webservices.netsuite.com">
         <name>phone</name>
    </nullFieldList>
       <q1:companyName>XYZ 2, Inc.</q1:companyName>
       <q1:fax>402-999-9999</q1:fax>
       <q1:email>bsanders@xyz.com</q1:email>
   </record>
  </update>
</soap:Body>
</soap:Envelope>

 

1 comment: