Bug in StateName field when creating/updating customer address?


I am not sure if this is a bug, but I am puzzled. When I am either creating or updating a customer address, I follow the following code:

// Update appropriate address information for Customer based on address type provided
foreach (QuantifyWebAPI.Classes.Address myAddress in myDeserializedClass.CustomerData.Addresses)
// Re-fetch customer record each time we update address data
customer = BusinessPartner.GetBusinessPartnerByNumber(myDeserializedClass.CustomerData.customer_id);
if (myAddress.addressTypeCode == “Business”)
customer.Addresses.GetAddressByType(AddressTypes.Business).Street = myAddress.address1;
customer.Addresses.GetAddressByType(AddressTypes.Business).Street1 = myAddress.address2;
customer.Addresses.GetAddressByType(AddressTypes.Business).City = myAddress.city;
customer.Addresses.GetAddressByType(AddressTypes.Business).StateName = myAddress.state;
customer.Addresses.GetAddressByType(AddressTypes.Business).PostalCode = myAddress.zip;
customer.Addresses.GetAddressByType(AddressTypes.Business).Country = myAddress.country;
else if (myAddress.addressTypeCode == “Billing”)
customer.Addresses.GetAddressByType(AddressTypes.Billing).Street = myAddress.address1;
customer.Addresses.GetAddressByType(AddressTypes.Billing).Street1 = myAddress.address2;
customer.Addresses.GetAddressByType(AddressTypes.Billing).City = myAddress.city;
customer.Addresses.GetAddressByType(AddressTypes.Billing).StateName = myAddress.state;
customer.Addresses.GetAddressByType(AddressTypes.Billing).PostalCode = myAddress.zip;
customer.Addresses.GetAddressByType(AddressTypes.Billing).Country = myAddress.country;
else if (myAddress.addressTypeCode == “Shipping”)
customer.Addresses.GetAddressByType(AddressTypes.Shipping).Street = myAddress.address1;
customer.Addresses.GetAddressByType(AddressTypes.Shipping).Street1 = myAddress.address2;
customer.Addresses.GetAddressByType(AddressTypes.Shipping).City = myAddress.city;
customer.Addresses.GetAddressByType(AddressTypes.Shipping).StateName = myAddress.state;
customer.Addresses.GetAddressByType(AddressTypes.Shipping).PostalCode = myAddress.zip;
customer.Addresses.GetAddressByType(AddressTypes.Shipping).Country = myAddress.country;

            // Validate and save the Customer record

When I run this code, everything works when creating the address except for the StateName field - this does not get populated even though I am certain I am passing in a valid 2 character code as a string (in my case “MN”).

Am I doing this wrong? Do I need to pass in a valid State GUID into State ID instead or something?

Please let me know if you need more code snippets or screenshots.
Thanks so much,

Hi Alex.

Do I need to pass in a valid State GUID into State ID instead or something?

That is correct.

State state = State.NewState();
state.Name = "CA";

address.StateID = state.StateID;

Does this only apply if it is a new State that has not been configured in Quantify yet?

If not, is there a method to get an existing State’s State ID based on the State Name?

Yes, this only applies if the state isn’t found. To determine if it exists, you can attempt to fetch it and then check the name. If the name matches what was fetched, then it exists, otherwise it will be a blank string. You can also check the ID, it will be an empty Guid if not found.

// Fetch state
State item = State.GetState("CA");
if (item.Name == "CA")
    System.Diagnostics.Debug.Print("State named CA exists");