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 :
Microsoft Dynamics AX (Archived)
Answered

createOrUpdatePostalAddress - What Property determines if it updates or creates?

(0) ShareShare
ReportReport
Posted on by

Hello everyone,

I am fairly new to Dynamics AX Development and I'm working in an environment that is running Dynamics AX 2012 R2.

I was wondering, what determines if createOrUpdatePostalAddress will create or update?

Here is a VERY basic example that I am working with.

DirPartyTable dirPartyTable = DirPartyTable::findByNum('000099734');
DirParty dirParty;
DirPartyPostalAddressView dirPartyPostalAddressView;

LogisticsPostalAddress logisticsPostalAddress;
DirPartyLocation dirPartyLocation;

dirParty = DirParty::constructFromCommon(dirPartyTable, DirUtility::getCurrentDateTime(), dirPartyTable.partyType());

dirPartyPostalAddressView.LocationName = 'Address';
dirPartyPostalAddressView.City = 'Some City';
dirPartyPostalAddressView.Street = '133 orange Street';
dirPartyPostalAddressView.CountryRegionId = 'USA';
dirPartyPostalAddressView.IsPrimary = NoYes::No;

dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);


In this very basic example, what do I need to add / change to make it do an update instead of creating this address over and over again?

I really appreciate any and all help on this.

Thank you so much!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Jie G Profile Picture
    Microsoft Employee on at

    Hi AnimalHealthCRM,

    According to the code logic of the createOrUpdatePostalAddress method:

    public DirPartyPostalAddressView createOrUpdatePostalAddress(DirPartyPostalAddressView _partyPostalAddressView, container _roles = conNull(), ValidTimeStateUpdate _validTimeStateUpdate = ValidTimeStateUpdate::CreateNewTimePeriod)
    {
        DirPartyPostalAddressView  newPartyPostalAddressView;
        LogisticsPostalAddress     postalAddress;
        LogisticsPostalAddressView postalAddressView;
        LogisticsPostalAddressEntity postalAddressEntity;
    
        if (!_partyPostalAddressView.Party)
        {
            _partyPostalAddressView.Party = this.getPartyRecId();
        }
    
        if (DirPartyLocation::findByPartyLocation(_partyPostalAddressView.Party, _partyPostalAddressView.Location))
        {
            postalAddress = LogisticsPostalAddress::findByLocation(_partyPostalAddressView.Location, true);
            postalAddressView.initFromPartyPostalAddressView(_partyPostalAddressView);
            postalAddressEntity = LogisticsPostalAddressEntity::construct(_partyPostalAddressView.Location);
            postalAddress = postalAddressEntity.initFromView(postalAddressView, postalAddress);
            postalAddress.validTimeStateUpdateMode(_validTimeStateUpdate);
            postalAddress.LogisticsPostalAddressMap::formatAddress();
            ttsbegin;
            postalAddress.update();
            ttscommit;
            newPartyPostalAddressView = DirPartyPostalAddressView::find(_partyPostalAddressView.Party, postalAddress.Location);
        }
        else
        {
            newPartyPostalAddressView = DirPartyLocationEntity::createAddressForParty(_partyPostalAddressView, _roles);
        }
    
        return newPartyPostalAddressView;
    }

    The findByPartyLocation method of DirPartyLocation table will create a DirPartyLocation object using DirPartyPostalAddressView's Party and Location property.
    Then check whether this record exists in the DirPartyLocation table. If it exists, it will update the DirPartyPostalAddressView, else a new DirPartyPostalAddressView will be created.
  • Community Member Profile Picture
    on at

    Hi,

    Refer the below link:

    msdynamicsxx2012.blogspot.com/.../find-or-update-customer-primary-address.html

    Note: createOrUpdatePostalAddress method is useful for both creating or updating the customer address. if you are providing the existing dirpartyid then it will update the customer address ,in case of new dirpartyid it will create a new address.

    I hope it answers your question.

  • Community Member Profile Picture
    on at

    Thank you both for taking the time to reach out to me on this.

    I truly appreciate all of the help!

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Sanhthosh.Kumar.K Profile Picture

Sanhthosh.Kumar.K 2

#2
Raed Salah Bzour Profile Picture

Raed Salah Bzour 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans