How to Replace a Primary in Address Cross Reference using WriteAddressRecord

I have a use case where my logic block would update a customer’s primary address. I tried to use the WriteAddressRecord logic block for adding a new address to the contact address cross reference. It inserted the new primary address to the customer’s contact address cross reference but the old one remains. Is there a way to remove the old one; i.e, effectively doing a primary address replacement? See the extra addresses below when I kept updating the primary addresses below:

Hey David — can you try calling WriteAddress instead of WriteAddressRecord? It is a wrapper LB that should determine whether or not an address already exists, and calls WriteAddressCrossRef if an address is found (by exact match) to update an existing record — OR it calls WriteAddressRecord, if one was not found to create a new address and address cross reference.

It is in WriteAddressCrossRef where we update an existing record.

1 Like

Ah, OK. I will switch to WriteAddress in my code. Thanks.

@tyler.pham, after switching to WriteAddress, I am not seeing the primary address updated. I only see the AddressTypes updated instead. The WriteAddress input parameters are like this:

Oh, my bad. I was copying an existing address to a variable and update the address fields but forgot to clear the AddressFull and AddressMultiline fields. After clearing those two fields, I am seeing the correct address in the app.

Perfect — okay thanks for clarifying.

@tyler.pham, I tried to use WriteAddress to update the primary address but still it does’t replace the old one. It just added the new primary address and unchecked the previous primary address:

It looks like WriteAddress internally is calling WriteAddressRecord, which would create the new primary address but not deleting the old one. I think I am back to square one.

I found a workaround:

  1. If the address to be updated to the directory is not in Addresses, i.e. not in the system, then insert the address into Addresses.
  2. Call WriteAddressCrossReference LB with this address to update the contact address cross reference for the directory.

1 Like

@david.lee how are you determining which address cross reference record to update the ContactAddress TL field to the newly created address from 1?

I don’t think we have a use case for this in the base product so I am actually just curious how this might be a normal thing to support.

Hi @tyler.pham, this is what I do

So I fetched the AddressCrossReference of a Directory record and then call the WriteAddressCrossRef with input field values for

AddressTypes = Main, Ship to

Contact(Directory) TL = nwId of the directory record

Contact Address = [InsertAddress]

Primary = True

Would the above work?

@tyler.pham, any other suggestion since WriteAddress still doesn’t replace the previous primary address in the address cross reference when the address is new and not in the system? In other words, WriteAddress adds the new primary address in the address cross reference but didn’t delete the old one. In my use case, it is done thru an integration; if I kept updating the primary address with new address not in the system, then I would need to keep manually removing the previous one(s) in the Customers app.

@tyler.pham you are right; what I tried to do as a workaround doesn’t work reliably.

I think I know what to do now. When I am adding a new primary address to the address cross reference table, I would delete the old one from the address cross reference table. Then call WriteAddress to add the new primary address to the Directory and Address Cross Reference.

1 Like