Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Retrieve an existing address for a specific customer

(0) ShareShare
ReportReport
Posted on by
Hello,
I have a requirement where I need to create a sales order from a web service.
The web service response will send information regarding the client and address information Address, LocationName, City, CountryRegionId and ZipCode.
If the 5 address field information have values then an address should be created for the customer.
We have noticed an issue with this as if several orders for the same client (and same address values) are being created, then technically the same address will be created multiple times.
To fix this, I have added a logic to check if an address based on the values exist for the customer in DirPartyPostalAddressView then I retrieve the postalAddressRecId instead of creating a new address.
However, the request is not returning any records.
I have created a test class to test but same results (The record exists for the values inserted when I checked in T-SQL):
DirPartyPostalAddressView   addressView;
        LogisticsPostalAddress postalAddress;
        DirPartyRecId party = 5637199605;
        utcdatetime datenow = DateTimeUtil::utcNow();
 
Request 1
        select firstonly1 validtimestate(datenow) postalAddress
            join  addressView
            order by addressView.IsPrimary desc
            where postalAddress.RecId == addressView._RecId_LogisticsPostalAddress && 
                  addressView.Party             == party &&
                  addressView.Address           == 'Address 123 %1' &&
                  addressView.LocationName      == 'ClientA' &&
                  addressView.City              == 'City1' &&
                  addressView.CountryRegionId   == 'CT' &&
                  addressView.ZipCode           == 'XXXXX';
 
Request 2
        select firstonly1 addressView
            order by addressView.IsPrimary desc
            where addressView.Party             == party &&
                  addressView.Address           == 'Address 123 %1' &&
                  addressView.LocationName      == 'ClientA' &&
                  addressView.City              == 'City1' &&
                  addressView.CountryRegionId   == 'CT' &&
                  addressView.ZipCode           == 'XXXXX';
 
Request 3
        select firstonly1 addressView
            order by addressView.IsPrimary desc
            where addressView.Party             == party &&
                  addressView.Address           == 'Address 123 %1' &&
                  addressView.LocationName      == 'ClientA' &&
                  addressView.City              == 'City1' &&
                  addressView.CountryRegionId   == 'CT' &&
                  addressView.ZipCode           == 'XXXXX' &&
addressView.ValidFrom <= datenow  &&
addressView.ValidTo >= datenow ;
 
All the requests are not returning any record.
Is there any way to retrieve an address based on this criteria?
  • Verified answer
    Jason0810M Profile Picture
    Jason0810M on at
    Retrieve an existing address for a specific customer
    Hello Andre,
    I have found the issue.
    Indeed there is a logic in the postLoad of the LogisticPostalAddressView which checks if the Address field value contains %1 and then sets it to the name of the record country region accordingly.
    I have done the same for my custom web service address field value and use it for the select statement.
    It works fine now.
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,735 Super User 2024 Season 2 on at
    Retrieve an existing address for a specific customer
    Hi Jason,
     
    It could be indeed related to "%1" in the address, but I'm not sure. Is this really a valid part of an address? Can you test with an address without this "%1"?
  • Jason0810M Profile Picture
    Jason0810M on at
    Retrieve an existing address for a specific customer
    Just as a note.
    I have noticed that the issue is probably due to the %1 symbol in the address.
    In T-SQL the address value of the record view is 'Address 123 %1' and same as the web service request.
    I have omitted the addressView.Address check in the select statement and it has ultimately returned the record with the addressView.Address field value being 'Address 123 TheCountryName' instead of 'Address 123 %1'.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans