web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

create/update postal address x++

(4) ShareShare
ReportReport
Posted on by 2,003
Hi,

What's the correct way to create addresses via code and to match standard?

for example this one inserts but doesn't update,

Also if I send an existing address, but only change locationName, then locationName doesn't get updated because of a method in the entity "resolveRemittanceAddressLocationId" which sees if everything matches an existing address by looking at lots of fields, locationName is not one of them

i thought if send a different locationName, then it will either update exsiting one or create a new address.. because in standard we are allowed to create two addresses with same details but different LocatioName
try
{
	if(_address)
	{
		CustTable custTable = CustTable::find(_custAccount);
		if(custTable)
		{
			DirPartyTable  dirPartyTable    = DirPartyTable::findRec(custTable.Party);

			DirPartyLocationPostalAddressV2Entity partyAddressEntity;

			partyAddressEntity.PartyNumber        =  dirPartyTable.PartyNumber;
			partyAddressEntity.Description        = _address.LocationName();
			partyAddressEntity.Street             = _address.Street();
			partyAddressEntity.City               = _address.City();
			partyAddressEntity.County             = _address.County();
			partyAddressEntity.State              = _address.State();
			partyAddressEntity.CountryRegionId    = _address.CountryRegionId();
			partyAddressEntity.ZipCode            = _address.PostCode();
			partyAddressEntity.Roles              = enum2Str(_roleType);
			if(_logisticsLocationId)
			{
				partyAddressEntity.LocationId     = _logisticsLocationId;
			}
			partyAddressEntity.insert();

			LogisticsPostalAddress logisticsPostalAddress = LogisticsPostalAddress::findByLocation(partyAddressEntity.RecId);
			postalAddressRecId = logisticsPostalAddress.RecId;
		}
	}
}
catch(Exception::Error)
{
	throw error('Error');
}

//then i use postalAddressRecId to set it in SalesTable.DeliveryPostalAddress

What' the best way to handle addresses?
Categories:
I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    303,988 Super User 2026 Season 1 on at
    Hi ..,
     
    In your coding, I only see an insert statement. Anyway, the postal addresses are date effective. That means that it supports versioning, In case of updating it will set a valid to date and will create a new record with the new information.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 653

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 493 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 317 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans