Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Customer Address Roles Update

Posted on by 3,732

Hi,

I'm working on the customer address update on the X++. Able to update the address details, but I cannot update the roles in that address. I had mentioned the code which I'm trying.

Code:

LogisticsPostalAddress address;
Custtable custtable;
DirPartyPostalAddressView addressView;
DirParty DirParty;
container roles;

custtable = Custtable::find("902536");
address.Location = 22565428539;
address.CountryRegionId = "USA";
address.State = "NY";
address.Street = "34";
address.ZipCode = "10119";
address.City = "new york";

addressView.Party = CustTable.Party;
addressview.initFromPostalAddress(address);
addressView.locationRoles();

DirParty = DirParty::constructFromPartyRecId(CustTable.Party);
roles = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Home).RecId];
DirParty.createOrUpdatePostalAddress(addressView, roles);

If I add the "address.Location = 22565428539;" means it update the address but it didn't update role detail. Can you give me the solution for it!!!

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Customer Address Roles Update

    Hi nikolaos,

    I tried the above two steps and I got the Expected result.

    Thanks!

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Customer Address Roles Update

    Hi Test Bot,

    are you dealing with the same requirement than mahiims18?

    My first suggestion was to delete all roles, then add role Other. That way you don't have to worry about the roles that the address might already have or not have.

    So, just follow that suggestion and you'll be fine.

  • Shaik146 Profile Picture
    Shaik146 932 on at
    RE: Customer Address Roles Update

    Hi nikolaos,

    I have got one doubt from your suggestion. If customer address having multiple roles i.e delivery and invoice. He can update the delivery to "other" and the invoice type can be found and deleted.

    Then what about the address with only of role type invoice. If he deletes it then how can he update dat role(i.e invoice) to other?

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Customer Address Roles Update

    In your previous code sample you have demonstrated how to fetch DirPartyLocationRole of type Delivery and update it to "Other". So you know how to fetch the record, and how to update it.

    Our next challenge is: "how to fetch DirPartyLocationRole of Invoice and delete it?" For this you need to know how to fetch records and how to delete records.

    We can split this challenge to two smaller steps:

    1) Fetch DirPartyLocationRole of Invoice

    2) Delete the DirPartyLocationRole record that was found in step 1.

    Could you please try these steps? And if you need help with something, just let me know which step it is and we can try to solve it together.

    Thanks!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Customer Address Roles Update

    I was clear what my code was doing I was struck in the next step like how to remove the role "Invoice", and how to achieve the correct format of role as I shared in the screen shot.

    Can you please correct my code to achieve the target.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Customer Address Roles Update

    Your code searched for all roles of "Delivery" and updated them to "Other". Is it clear to you what your code does, and why it did what it did?Once it is clear to you, I think the next step will be super easy. You're almost there. Now you only need to remove the role "Invoice".

    Since we have already learned how to add and update roles, we definetely know how to remove a role. Want to give it a try?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Customer Address Roles Update

    Currently the address has two roles, and you want to remove them and add one new role. Correct? - Yes Nikolaos this is what I expected

    while select dirPartyLocationRole

                       exists join dirPartyLocation join logisticsLocationRole

                           where dirPartyLocation.Party == custTable.Party

                           && dirPartyLocation.IsPostalAddress == NoYes::Yes

                           && dirPartyLocation.IsPrimary == NoYes::No

                           && dirPartyLocationRole.PartyLocation == dirPartyLocation.RecId

                           && dirPartyLocationRole.LocationRole == logisticsLocationRole.RecId

                              && (logisticsLocationRole.Name == enum2Value(LogisticsLocationRoleType::Delivery))

                              // || logisticsLocationRole.Name == enum2Value(LogisticsLocationRoleType::Invoice))

                       {

                           ttsBegin;

                           dirPartyLocationRole.selectForUpdate(true);

                           dirPartyLocationRole.LocationRole = LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Other).RecId;

                           dirPartyLocationRole.doupdate();

                           ttsCommit;

                       }

    This was my code snippet, Here I can able to update only role either Delivery or Invoice .

    If I update the Delivery role it is showing Invoice; other but expected is like shown below.

    pastedimage1606214270547v1.jpeg

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Customer Address Roles Update

    Ok,

    I have explained to you how to add a third role in a scenario where you have two existing roles. The solution was to add one more record in DirPartyLocationRole table. So, each record in that table corresponds to one role in the address. By adding and removing records we can control the roles for the address. So far so good.

    Currently the address has two roles, and you want to remove them and add one new role. Correct? I actually think that we're quite close to a solution. Can you already develop it, based on these inputs?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Customer Address Roles Update

    Currently I have two roles like Delivery; Invoice and the target is only one role i.e. role of type "other",

    I have to update these two roles(Delivery; Invoice) with one role (other).

    In the end the customer has only one role i.e.. 'other'.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Customer Address Roles Update

    You need to have one record in DirPartyLocationRole for each role. So if the address should have three roles, then you need to have three records in DirPartyLocationRole. If you currently have 2, you need to insert one more.

    You need to provide values in two fields:

    - LocationRole: RecId of the LogisticsLocationRole that you want to assign

    - PartyLocation: RecId of the LogisticsLocation of the address

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans