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

Community site session details

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

create/update postal address x++

(0) ShareShare
ReportReport
Posted on by 1,907
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)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,771

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 806 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 542 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans