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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Answered

Updating Vendor Address using X++

(0) ShareShare
ReportReport
Posted on by 2,426

Good Morning,

I am trying to update Vendor Address only State Field for all vendors through excel

not through DMF(Because i want to update Tax information also for every vendor)

Can i achieve his through DMF or X++ ?

Which tables should i update.

I am really Confused.

Please help.

Regards.

Have  a great day.

*This post is locked for comments

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
  • AX 2012 r3 Profile Picture
    2,426 on at

    Hi Vilmos,

    Thanks for your quick reply,

    i have seen this blog.

    i am updating.So i am searching for updating.

    i am searching how state is achieved first

    i.e through Vendtable.PostalAddress().state;

    So i will go backwards and will see postaladdress() and i will update as according to that.

    Suggest me if i am Wrong.

    Regards.

    Have a great day Vilmos.

  • Vilmos Kintera Profile Picture
    46,149 on at

    I am unsure what you are doing, but what is needed for updating or creating address or any other contact information is via the view mentioned in the articles.

  • AX 2012 r3 Profile Picture
    2,426 on at

    Hi,

    New GST is calculating on State code.

    So,They want to change State for all vendors.

    Regards.

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Vendor address state value can be retrieved from tables VendTable, DirPartyTable, DirPartyLocation, LogisticsLocation and LogisticsPostalAddress (or) through the view DirPartyPostalAddressView(mentioned in the blogs suggested by Vilmos)

    You can use the following job(query) to get the data and to update the state:
    static void VendorState(Args _args)
    {
    VendTable vendTable;
    DirPartyTable dirPartyTable;
    DirPartyLocation dirPartyLocation;
    LogisticsLocation logisticsLocation;
    LogisticsPostalAddress logisticsPostalAddress;
    LogisticsAddressState LogisticsAddressState;

    while select vendTable
    where vendTable.AccountNum == "Vend1" // Vendor
    join dirPartyTable
    where vendTable.Party == dirPartyTable.RecId
    join dirPartyLocation
    where dirPartyLocation.Party == dirPartyTable.RecId
    && dirPartyLocation.IsPostalAddress == true
    //&& dirPartyLocation.IsPrimary == true // To get primary address
    join logisticsLocation
    where logisticsLocation.RecId == dirPartyLocation.Location
    && logisticsLocation.Description == "AddressDescription" // Address description
    join logisticsPostalAddress
    where logisticsPostalAddress.Location == dirPartyLocation.Location
    {
    // Older state
    info(strFmt("State: %1", logisticsPostalAddress.State));

    // Newer state - Check on the new state
    if (LogisticsAddressState::exist(logisticsPostalAddress.CountryRegionId, "NewState"))
    {
    ttsBegin;
    logisticsPostalAddress.selectForUpdate(true);
    logisticsPostalAddress.ValidTimeStateUpdateMode (ValidTimeStateUpdate::Correction);
    logisticsPostalAddress.State = "NewState";
    logisticsPostalAddress.update();
    ttsCommit;
    }
    }

    }

    Hope this helps you.

    Thanks,
    Chaitanya Golla

  • Suggested answer
    Ajit Profile Picture
    8,788 on at

    I believe it would be good to use the view instead of using multiple joins if possible.

    We can get recid of LogisticsPostalAddress from that view using party and 'IsPrimary' checkbox and then select the buffer of that table and update the state.

  • Verified answer
    AX 2012 r3 Profile Picture
    2,426 on at

    Hi Chaitanya,

    Thank you so much for reply.

    we can update logisticpostal address.state.

    This piece of code will do

    //To Update
    VendTable vendtable;
    LogisticsPostalAddress postalAddress;
    DirPartyLocation partyLocation;
    EffectiveDateTime fromdate;
    ExpirationDateTime todate;
    ttsBegin;
    select firstFast vendtable where vendtable.AccountNum == "INMF-000001";

    select forUpdate firstOnly postalAddress
    exists join partyLocation
    where partyLocation.Location == postalAddress.Location
    && partyLocation.IsPrimary == true
    && partyLocation.Party == vendtable.Party;
    postalAddress.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
    postalAddress.State = "Andhra";
    postalAddress.ValidFrom = DateTimeUtil::getSystemDateTime();
    postalAddress.ValidTo = DateTimeUtil::maxValue();
    postalAddress.doUpdate();
    ttsCommit;
    info("Updated");

    Relation :-

    Vendtable ==  vendtable::find("INMF-000001");

    vendtable.party == dirpartylocation.party;

    dirpartylocation.location == logisticspostaladdress.location //Here u will get Multiple Records whether primary and not primary records .Update based on condition.If all need to be updated Use while here

    //Upto here it is updated succesfully.

    //Go and check in view whether it is updated or not.We didnot update View in code.But it is updated.

    //The relation continues

    Logisticspostaladdress.recid == dirpartypostaladdressview._recid_logisticspostaladdress //Here it is updated Automatically.No need to update in View.

     

     

    If i am wrong.Please correct.

    Regards.

    Have a great day.

  • Verified answer
    AX 2012 r3 Profile Picture
    2,426 on at

    And to update Address .

    Because i have updated through form.when state is changed.then Address is also changing.

    So,Update Address also

    Please use this piece of code.

    postalAddress.Address = LogisticsPostalAddress::formatAddress(postalAddress.Street,postalAddress.ZipCode,postalAddress.City,postalAddress.CountryRegionId,postalAddress.State,postalAddress.County,postalAddress.DistrictName,postalAddress.StreetNumber,postalAddress.BuildingCompliment,postalAddress.PostBox);

    Regards

    Have a great day.

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 Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans