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 NAV (Archived)

Updating Sales Order

(0) ShareShare
ReportReport
Posted on by

Om trying to create a check which when the user closes the customer card it should check to see if any of the Address fields Have changed. If it has it should then change the sales orders relating to that customer with the correct Information.

Currently I have came up with this quickly, however how can i Make it more efficient. 

Customer Card (OnOpenPage)


Rec := recCustomer1;
grecCustomer2 := recCustomer1;

Customer Card (OnClosePage)

cuLewisDev.CustomerAddressamendment(recCustomer1,grecCustomer2);

In the Codeunit


CustomerAddressamendment(grecCustomer2 : TEMPORARY Record Customer;recCustomer1 : Record Customer)
IF recCustomer1.Address <> grecCustomer2.Address THEN
UpdateSalesorder(recCustomer1, grecCustomer2);
IF recCustomer1."Address 2" <> grecCustomer2."Address 2" THEN
UpdateSalesorder(recCustomer1, grecCustomer2);
IF recCustomer1.City <> grecCustomer2.City THEN
UpdateSalesorder(recCustomer1, grecCustomer2);
IF recCustomer1.Contact <> grecCustomer2.Contact THEN
UpdateSalesorder(recCustomer1, grecCustomer2);
IF recCustomer1.Name <> grecCustomer2.Name THEN
UpdateSalesorder(recCustomer1, grecCustomer2);
IF recCustomer1."Post Code" <> grecCustomer2."Post Code" THEN
UpdateSalesorder(recCustomer1, grecCustomer2);
IF recCustomer1.City <> grecCustomer2.City THEN
UpdateSalesorder(recCustomer1, grecCustomer2);

UpdateSalesorder(recCustomer1 : Record Customer;grecCustomer2 : TEMPORARY Record Customer)
recSalesOrder.RESET;
recSalesOrder.SETRANGE("Sell-to Customer No.", recCustomer1."No.");
IF recSalesOrder.FINDSET(TRUE,FALSE) THEN
IF CONFIRM('Do you want to Update Sales order',FALSE) = FALSE THEN
EXIT;
recSalesOrder."Bill-to Name" := recCustomer1.Name;
recSalesOrder."Bill-to Address 2" := recCustomer1."Address 2";
recSalesOrder."Bill-to Address" := recCustomer1.Address;
recSalesOrder."Bill-to City" := recCustomer1.City;
recSalesOrder."Bill-to Post Code" := recCustomer1."Post Code";
recSalesOrder."Bill-to Contact" := recCustomer1.Contact;
recSalesOrder.MODIFY;

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Binesh Profile Picture
    7,887 on at

    Hello

    See the Customer Table onModify Code

    in this See functin UpdateContFromCust.OnModify(Rec);

    now you create function like:

    UpdateAddressFromCust.OnModify(Rec);  //New Codeunit with Cust

    in that function instead of Cont put SalesHeader Rec Variable.

    filter as per relation and make changes, then SalesHeader.MODIFY(TRUE);

  • ManishS Profile Picture
    86 on at

    I think you should write code on OnQueryClosePage, cause if any error occures then OnclosePage will not close.

  • Community Member Profile Picture
    on at

    Thank you for your response. In the example above. I'm trying to set the current record into a temporary variable Rec := grecCustomer2; but following the debugger it doesn't work. What do i need to change?

  • Verified answer
    Binesh Profile Picture
    7,887 on at

    Your code is wrong, You wrote

    Rec := recCustomer1;

    Now Rec is empty, because recCustomer1 is empty;

    You have to write

    recCustomer1 := Rec;

    ///////2nd -----.////

    cuLewisDev.CustomerAddressamendment(recCustomer1,grecCustomer2);

    In the Codeunit

    CustomerAddressamendment(grecCustomer2 : TEMPORARY Record Customer;recCustomer1 : Record Customer)

    IF recCustomer1.Address <> grecCustomer2.Address THEN

    UpdateSalesorder(recCustomer1, grecCustomer2);

    Means what?

    You are passing Customers, means here

    recCustomer1 and grecCustomer2 both are same.

    You need to pass only Cust as a var TRUE

    and in function Filter SalesHeader cust

    and now need to check

    with REPEAT..UNTIL and Now Modify SalesHeader Address with Cust.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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
TAHER_El_Mehdi Profile Picture

TAHER_El_Mehdi 2

#1
sliderxb Profile Picture

sliderxb 2

#1
broberts Profile Picture

broberts 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans