通过 SuiteTalk Webservices 访问 Netsuite 中的客户默认送货地址

Accessing Customer Default Shipping Address in Netsuite via SuiteTalk Webservices

我很难找到这个,所以我想分享(发布我自己的答案),特别是因为那里的 NetSuite 代码示例似乎很少。

NetSuite 中的默认地址与指定地址是否为默认地址的复选框字段不同。复选框字段表示为 defaultShippingSpecified,但我需要弄清楚如何访问该字段。

以下是我查找所有客户地址并将指定地址标记为默认地址的方法。这与获取销售订单行并使用 'ship to' 信息填充这些行的功能一起运行。

        private Dictionary<string, string> getCustomerAddressID(String customerInternalID)
    {
        RecordRef customerRef = new RecordRef
        {
            internalId = customerInternalID,
            type = RecordType.customer,
            typeSpecified = true
        };

        Dictionary<string, string> listOfAddresses = new Dictionary<string, string>();

        ReadResponse readResponse = _service.get(customerRef);
        if (readResponse.status.isSuccess)
        {
            //type cast to get "instance" of record
            Customer customer = (Customer)readResponse.record;

            //var addressBookList = customer.addressbookList;
            var defaultShippingInternalID = "";
            var addrBook = customer.addressbookList.addressbook;

            foreach (CustomerAddressbook addr in addrBook)
            {
                if (addrBook.Length == 1 || addr.defaultShippingSpecified)
                {
                    defaultShippingInternalID = addr.internalId;
                    listOfAddresses.Add("default", defaultShippingInternalID);
                }
                else { listOfAddresses.Add("alternate", addr.internalId); }
            }
        }
        else
        {
            Console.WriteLine("Get customer Failed");
            displayError(readResponse.status.statusDetail);
        }
        return listOfAddresses;
    }