External Document No. on Sales Order Header (Nav 2018)

Kwajahat
Member Posts: 10
Hi,
I would like to know how to write a simple piece of code where under sales order header there is an field called External Document No.; If for a customer A, I have already entered the external doc no. as Testing and post the order, that's fine since it is the first time entry with such a external document number. What if I select the same customer, create another sales order for him but use the same external document no. as Testing, I want Nav to validate that duplicate external document no and prompt a message for me to say that such document number was already used
I am a functional guy but since this request came from one of my customer I would like to know if this change can be done by me if anyone of you can guide me with proper steps of doing it. I hope to see some replies on this topic
Regards
Kwaja
I would like to know how to write a simple piece of code where under sales order header there is an field called External Document No.; If for a customer A, I have already entered the external doc no. as Testing and post the order, that's fine since it is the first time entry with such a external document number. What if I select the same customer, create another sales order for him but use the same external document no. as Testing, I want Nav to validate that duplicate external document no and prompt a message for me to say that such document number was already used
I am a functional guy but since this request came from one of my customer I would like to know if this change can be done by me if anyone of you can guide me with proper steps of doing it. I hope to see some replies on this topic
Regards
Kwaja
0
Answers
-
In "OnValidate" of External Document No. on Sales Header table:
salesheader2: record of subtype sales header SalesHeader2.SETRANGE("Document Type", SalesHeader."Document Type"::Order); SalesHeader2.SETRANGE("Sell-to Customer No.", "Sell-to Customer No."); //from the current record SalesHeader2.SETRANGE("External Document No.", "External Document No."); //from the current record IF NOT SalesHeader2.ISEMPTY THEN Error('Sales order for customer X with external document number Y already exists');
0 -
Hi Phogue
Thank you so much for the reply and also for the small code that you have given for me to write. I shall copy and paste it on the sales header table under the onvalidate of external doc no. and test it out
Thanks
Regards
Kwaja0 -
First, you should make an exclusion when External Document No. is blank. Then, you need to make sure to exclude the current order itself in case some code validates the field without actually changing the value. Another suggestion from me would be to also look at Posted Sales Invoices. I think that should be done because one user may have already posted an order with for such Customer with such External Document No. and your check would ignore that. So your full code would become:
IF "External Document No." = '' THEN EXIT; SalesHeader2.SETRANGE("Document Type", SalesHeader."Document Type"::Order); SalesHeader2.SETRANGE("Sell-to Customer No.", "Sell-to Customer No."); //from the current record SalesHeader2.SETRANGE("External Document No.", "External Document No."); //from the current record SalesHeader2.SETFILTER("No.", '<>%1', "No."); //if somebody manages to VALIDATE "External Document No." without changing it, you would get an error due to the order itself IF NOT SalesHeader2.ISEMPTY THEN Error('Sales order for customer %1 with external document number %2 already exists', "Sell-to Customer No.", "External Document No."); SalesInvoiceHeader.SETRANGE("Sell-to Customer No.", "Sell-to Customer No."); //from the current record SalesInvoiceHeader.SETRANGE("External Document No.", "External Document No."); //from the current record IF NOT SalesInvoiceHeader.ISEMPTY THEN Error('Sales order for customer %1 with external document number %2 has already been posted', "Sell-to Customer No.", "External Document No.");
1
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions