Example of Setting a List/Record Segment Value
The following example shows how to set a value for a custom segment of type List/Record. Specifically, this example shows how to add an inventory item record and set a value for the segment as part of the add request. This example assumes that the segment has already been created with a series of possible values. This example also assumes that the segment has already been applied to the inventory item record type.
C#
private void addInventoryItem()
{ // If this is a OneWorld account, define a // subsidiary. RecordRef mySubsidiary = new RecordRef(); mySubsidiary.internalId = "1"; RecordRef[] subsidiaries = new RecordRef[1]; subsidiaries[0] = mySubsidiary; // Define a tax schedule. RecordRef myTaxSchedule = new RecordRef(); myTaxSchedule.internalId = "2"; // Define values for the item record's body fields. InventoryItem myItem = new InventoryItem(); myItem.externalId = "9063BA1"; myItem.displayName = "Cashmere Mittens"; myItem.itemId = "Cashmere Mittens"; myItem.taxSchedule = myTaxSchedule; myItem.subsidiaryList = subsidiaries; // Define an object to represent the segment field. Because the segment // if of type List/Record, you must use SelectCustomFieldRef. SelectCustomFieldRef selectCustomFieldRef = new SelectCustomFieldRef(); // Define an object to represent the segment's value. ListOrRecordRef custSelectValue = new ListOrRecordRef(); custSelectValue.internalId = "1"; // Set the value of the custom field object. selectCustomFieldRef.value = custSelectValue; // Identify the specific segment for which you are setting a value. // Use the script ID of the segment field as it appears on // an instance of the inventory item record. selectCustomFieldRef.scriptId = "cseg_profitcenter"; // Define an array of CustomFieldRefs that includes the selectCustomFieldRef you // just created. (Recall that CustomFieldRef is an abstract class that // represents both SelectCustomFieldRef and MultiSelectCustomFieldRef.) // Set the item's customFieldList as being equal to this array. CustomFieldRef[] customFieldRefArray = new CustomFieldRef[1]; customFieldRefArray[0] = selectCustomFieldRef; myItem.customFieldList = customFieldRefArray; // Add the item. _service.add(myItem); }
SOAP Request
<soap:Body>
<add xmlns="urn:messages_2017_1.platform.webservices.netsuite.com">
<record externalId="9063BA1" xsi:type="q1:InventoryItem" xmlns:q1="urn:accounting_2017_1.lists.webservices.netsuite.com">
<q1:taxSchedule internalId="2"/>
<q1:itemId>Cashmere Mittens</q1:itemId>
<q1:displayName>Cashmere Mittens</q1:displayName>
<q1:subsidiaryList>
<recordRef internalId="1" xmlns="urn:core_2017_1.platform.webservices.netsuite.com"/>
</q1:subsidiaryList>
<q1:customFieldList>
<customField scriptId="cseg_profitcenter" xsi:type="SelectCustomFieldRef" xmlns="urn:core_2017_1.platform.webservices.netsuite.com">
<value internalId="1"/>
</customField>
</q1:customFieldList>
</record>
</add>
</soap:Body>
SOAP Response
<soapenv:Body>
<addResponse xmlns="urn:messages_2017_1.platform.webservices.netsuite.com">
<writeResponse>
<platformCore:status isSuccess="true" xmlns:platformCore="urn:core_2017_1.platform.webservices.netsuite.com"/>
<baseRef xsi:type="platformCore:RecordRef" type="inventoryItem" externalId="9063BA1" internalId="346" xmlns:platformCore="urn:core_2017_1.platform.webservices.netsuite.com"/>
</writeResponse>
</addResponse>
</soapenv:Body>