Skip to main content

Notifications

Announcements

No record found.

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

  • Verified answer
    Binesh Profile Picture
    7,885 on at
    RE: Updating Sales Order

    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.

  • Community Member Profile Picture
    on at
    RE: Updating Sales Order

    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?

  • ManishS Profile Picture
    80 on at
    RE: Updating Sales Order

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

  • Suggested answer
    Binesh Profile Picture
    7,885 on at
    RE: Updating Sales Order

    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);

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics NAV (Archived)

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans