Help with a code on Codeunit 81

DarkHorse
Member Posts: 389
Dear fiolks, on Codeunit 81-Sales Post(Yes/No) I've the following code on Code trigger.
I've created a new table called "reserva", when a sales order is going to register this code go to the "reserva" table and looks for if the item is reserved and for which customer. If the sales order is for that customer it lets to register but if is for another customer then don`t let to resgister unless there is enough quantity for reserve and for register.
It works perfectly, but now I want that it advise me (with a message) if there is a reserved quantity for another customer (or for the same customer) of the same item. I mean, first show the message 'You can't register, there is a reserved quantity' and after, if there is another reserved from that item, shows 'Also there is another reserve fot that item". What is missing in my code?. I guess that it must turn to go over all the table again, but I don't get it.
Thanks in advance.
salesline.RESET; salesline.SETRANGE("Document Type", SalesHeader."Document Type"); salesline.SETRANGE("Document No.", SalesHeader."No."); salesline.SETRANGE("Sell-to Customer No.", SalesHeader."Sell-to Customer No."); reserva.RESET; IF reserva.GET(salesline."Sell-to Customer No.")THEN; IF salesline.FIND('-')THEN BEGIN; IF reserva.FIND('-') THEN REPEAT reserva.CALCFIELDS("Existencias producto"); cant:=reserva."Item quantity"-reserva."Reserved quantity"; IF (salesline."No."=reserva."Item") AND (reserva."Nº customer"<>salesline."Sell-to Customer No.") AND (salesline.Quantity>cant) AND (reserva.Reserved=TRUE) AND (reserva."Stop reserve"=FALSE) THEN ERROR('You can't register, there is a reserved quantity'); UNTIL reserva.NEXT=0;
I've created a new table called "reserva", when a sales order is going to register this code go to the "reserva" table and looks for if the item is reserved and for which customer. If the sales order is for that customer it lets to register but if is for another customer then don`t let to resgister unless there is enough quantity for reserve and for register.
It works perfectly, but now I want that it advise me (with a message) if there is a reserved quantity for another customer (or for the same customer) of the same item. I mean, first show the message 'You can't register, there is a reserved quantity' and after, if there is another reserved from that item, shows 'Also there is another reserve fot that item". What is missing in my code?. I guess that it must turn to go over all the table again, but I don't get it.
Thanks in advance.
0
Comments
-
My question: why you created this? It is standard NAV functionality. Use Orders (or Blank Orders) for reservation.0
-
Thanks for reply. I know there is a funcionality for it, thanks for alerting, but I've done this, more easy for people and only with just we need.
Thanks.0 -
As was said, this is standard functionality. Don't reinvent the wheel if you don't have to. But if you must...
It seems like your design is wrong. You have a GET statement on your custom table. GET works with the primary key of the table, which appears to be a Customer No. If you're reserving multiple items for the same customer, how does your code work?but now I want that it advise me (with a message) if there is a reserved quantity for another customer (or for the same customer) of the same item
Since there can only be one entry per customer in your table, the "(or for the same customer)" will never happen.
Think about using the standard functionality. It will make life easier in the long run.0 -
Since there can only be one entry per customer in your table, the "(or for the same customer)" will never happen.
It's correct, sorry :oops: . I mean only when there is more than one reserve of the same item. It's possible?.
Thanks for help.0 -
Any solution please? [-o<
Thanks.0 -
From my point of view, you are trying to do two different things at the same time. Split them.
Means, at first check for reservation and if it is not the required result, do second step and find is it reserved for another customer. This is easier.0 -
Thanks for reply. According to this code, how it would be please?.
Thanks for help.0 -
Are reserva."Item quantity" and reserva."Reserved quantity" flowfields?
What is a structure of reserva table.
At least I need more information to write you an example.0 -
Thanks for reply. I tell you. reserva."Item quantity" it's a flowfield. (from table Item). I post some information about "reserva" table.
keys: Cód. item,Nº customer,Reserved quantity,Reservr,Stop reserve
Nº linea,Posting Date,Cód. item,Nº customer
Cód. item,Reserve
Nº customer
the fields:
Field No. Field Name Caption Data Type Length Description Field Class Option String
1 Cód. item <Cód. producto> Code 30 Normal
2 Nº customer <Nº cliente> Code 20 Normal
3 Reserved quantity <Cantidad a reservar> Decimal Normal
4 Description Descripción Text 50 Normal
5 Name Nombre Text 40 Normal
6 Posting Date Fecha registro Date Normal
10 Reservar <Reservar> Boolean Normal
29 Salesperson Code Cód. vendedor Code 10 Normal
32 Vendor No. Nº proveedor Code 20 Normal
33 Familia <Familia> Code 10 Normal
34 Product <Product> Text 30 Normal
35 Nº linea <Nº linea> Integer Normal
38 Customer Posting Group <Customer Posting Group> Code 10 Normal
39 Item quantity <Existencias producto> Decimal FlowField
40 Stop reserve <Anular reserva> Boolean Normal
41 Blocked <Bloqueado> Option FlowField ,Ship,Invoice,All,Commercial
Thanks you for help.0 -
I've tried, but this takes a lot of time and will be about 100 lines (i think), so i will say only some tricks due to not program for others in the future
.
1. You need to use temporary tables to manage lines that you want to check (sales lines) and reserva table lines to know what is left if more than one line with the same item exists in the same document.
2. At first go through existing lines (in salesline temporary table) and reduce the quantities that are reserved.
3. Go again and find do you have any other reservation.
Hope this helps.0 -
Thank you very much for help. I'll try that you say.
Thanks for help.0
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