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

时间:2015-10-09 09:37:16

标签: c# web-services netsuite

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

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

1 个答案:

答案 0 :(得分:0)

以下是查找所有客户地址的方法,并将指定的地址标记为默认地址。这与一个函数一起运行,以获取销售订单行并使用“发送到”信息填充行。

        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;
    }