web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Suggested answer
    Binesh Profile Picture
    7,885 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,885 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans