# How to Replace a Primary in Address Cross Reference using WriteAddressRecord

**URL:** <https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436>\
**Category:** Foundation\
**Created:** [November 6, 2025, 2:35pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436 "2025-11-06T14:35:51Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![david.lee](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/david.lee/32/331_2.png) [@david.lee](https://community.nextw.com/u/david.lee)\
**Post date:** [November 6, 2025, 2:35pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/1 "2025-11-06T14:35:51Z")

</div>

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:

 ![Screenshot 2025-11-06 at 6.04.35 AM](https://us1.discourse-cdn.com/flex001/uploads/nextworld/original/1X/20f63fd83941242d386ab39ed08f65b0542dc976.png)

---

<div class="post-metadata">

**Author:** ![tyler.pham](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/tyler.pham/32/218_2.png) [@tyler.pham](https://community.nextw.com/u/tyler.pham)\
**Post date:** [November 6, 2025, 4:40pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/2 "2025-11-06T16:40:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![david.lee](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/david.lee/32/331_2.png) [@david.lee](https://community.nextw.com/u/david.lee)\
**Post date:** [November 6, 2025, 5:25pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/3 "2025-11-06T17:25:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david.lee](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/david.lee/32/331_2.png) [@david.lee](https://community.nextw.com/u/david.lee)\
**Post date:** [November 6, 2025, 5:53pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/4 "2025-11-06T17:53:00Z")

</div>

@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:

 ![WriteAddressParameters](https://us1.discourse-cdn.com/flex001/uploads/nextworld/original/1X/f60e4d703be76fb54de6d1709deb7376b2b80edc.png)

---

<div class="post-metadata">

**Author:** ![david.lee](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/david.lee/32/331_2.png) [@david.lee](https://community.nextw.com/u/david.lee)\
**Post date:** [November 6, 2025, 6:20pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/5 "2025-11-06T18:20:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tyler.pham](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/tyler.pham/32/218_2.png) [@tyler.pham](https://community.nextw.com/u/tyler.pham)\
**Post date:** [November 6, 2025, 6:20pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/7 "2025-11-06T18:20:46Z")

</div>

Perfect — okay thanks for clarifying.

---

<div class="post-metadata">

**Author:** ![david.lee](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/david.lee/32/331_2.png) [@david.lee](https://community.nextw.com/u/david.lee)\
**Post date:** [November 6, 2025, 6:24pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/8 "2025-11-06T18:24:41Z")

</div>

@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:

 ![image](https://us1.discourse-cdn.com/flex001/uploads/nextworld/original/1X/361e44b577c251ba5035aff844fa9e7ccbacae0a.png)

---

<div class="post-metadata">

**Author:** ![david.lee](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/david.lee/32/331_2.png) [@david.lee](https://community.nextw.com/u/david.lee)\
**Post date:** [November 6, 2025, 6:35pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/9 "2025-11-06T18:35:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![david.lee](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/david.lee/32/331_2.png) [@david.lee](https://community.nextw.com/u/david.lee)\
**Post date:** [November 6, 2025, 6:41pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/10 "2025-11-06T18:41:24Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex001/uploads/nextworld/original/1X/698cdac6064781c6e29c703d3f4235f8882d4963.png)

---

<div class="post-metadata">

**Author:** ![tyler.pham](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/tyler.pham/32/218_2.png) [@tyler.pham](https://community.nextw.com/u/tyler.pham)\
**Post date:** [November 6, 2025, 6:51pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/11 "2025-11-06T18:51:03Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![david.lee](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/david.lee/32/331_2.png) [@david.lee](https://community.nextw.com/u/david.lee)\
**Post date:** [November 6, 2025, 9:58pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/12 "2025-11-06T21:58:19Z")

</div>

Hi @tyler.pham, this is what I do

 ![image](https://us1.discourse-cdn.com/flex001/uploads/nextworld/original/1X/9a5ad090d754e0741e9cde94a039c7471fbc2823.png)

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?

---

<div class="post-metadata">

**Author:** ![david.lee](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/david.lee/32/331_2.png) [@david.lee](https://community.nextw.com/u/david.lee)\
**Post date:** [November 7, 2025, 5:17pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/13 "2025-11-07T17:17:01Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![david.lee](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/david.lee/32/331_2.png) [@david.lee](https://community.nextw.com/u/david.lee)\
**Post date:** [November 7, 2025, 6:51pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/14 "2025-11-07T18:51:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david.lee](https://sea1.discourse-cdn.com/flex001/user_avatar/community.nextw.com/david.lee/32/331_2.png) [@david.lee](https://community.nextw.com/u/david.lee)\
**Post date:** [November 7, 2025, 8:58pm UTC](https://community.nextw.com/t/how-to-replace-a-primary-in-address-cross-reference-using-writeaddressrecord/1436/15 "2025-11-07T20:58:49Z")

</div>

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.
