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 Microsoft Employee

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
    Binesh 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
    Community Member Microsoft Employee 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
    ManishS 78 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
    Binesh 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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans