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

Announcements

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,009
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
    305,842 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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 463 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

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

#3
Subra Profile Picture

Subra 392

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans