how to ban the same item (Article ) on two lines orders

slige83
Member Posts: 2
Hi,
how to ban the same item (Article ) on two lines orders
Thanks
how to ban the same item (Article ) on two lines orders
Thanks
0
Answers
-
You cannot - you need a customisation to achieve this.
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
For a two lines order you can add below code on the "OnInsert" Trigger of Purchase Line / Sales Line Table "
IF "Line No." > 0 THEN IF xRec."No." = Rec."No." THEN ERROR ('You cannot add same Item No. on 2 lines');
0 -
For a two lines order you can add below code on the "OnInsert" Trigger of Purchase Line / Sales Line Table "
IF "Line No." > 0 THEN IF xRec."No." = Rec."No." THEN ERROR ('You cannot add same Item No. on 2 lines');
I sense that check must cover every line so:IF "Line No." > 0 THEN BEGIN SalesLine2.RESET; SalesLine2.SETFILTER("No.", Rec."No."); IF SalesLine2.FINDSET THEN REPEAT IF SalesLine2."No." = Rec."No." THEN ERROR ('You cannot add same Item No. on 2 lines'); UNTIL SalesLine2.NEXT = 0; END;
0 -
All good, except this is almost an anti-pattern.
It should be more like this:IF (Type = TYpe::Item) AND ("No." <> '') THEN BEGIN SalesLine2.RESET; SalesLine2.SETRANGE("Document No.", "Document No."); SalesLine2.SETFILTER("Line No.", '<>%1', "Line No."); SalesLine2.SETRANGE(Type, Type); SalesLine2.SETRANGE("No.", "No."); IF NOT SalesLine2.ISEMPTY THEN ERROR('...'); END;
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031 -
I believe there are many ways to handle this, depends on how and when you wanted this to be implemented and executed.
Better way is to handle it right way on the No column as soon as User enters the same Item No.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
Hi Pn7,
Checking the same for every line the code provided by you will work.
Thanks
0 -
No. - OnValidate()
SL2.RESET;
SL2.SETRANGE("Document Type","Document Type");
SL2.SETRANGE("Document No.","Document No.");
SL2.SETRANGE("No.","No.");
IF SL2.FIND('-') THEN
ERROR('You cannot add same Item No. on 2 lines');0 -
Hi All,
Just an update, with the below code added on "OnValidate Trigger" of No. Field we cannot create even the second purchase Order with same Item if the first Purchase order is not fully received and invoiced (and moved to achieve)IF (Type = Type::Item) AND ("No." <> '') THEN BEGIN PurchLine2.RESET; PurchLine2.SETRANGE("No.", Rec."No."); IF PurchLine2.FINDSET THEN REPEAT IF PurchLine2."No." = Rec."No." THEN ERROR ('You cannot add same Item No. on 2 lines'); UNTIL PurchLine2.NEXT = 0; END;
Seems not feasible for all scenarios.
Thanks in advance.0 -
That is unfortunately a fate of most restrictions - they don't do very well in various scenarios, and require constant refining and refining. Adn quite often missed consequence is that users slowly stop using their brain - after all system will let them, or will not. And if they do some stupid thing the excuse is - but the system let me....
Rather than spending time on inventing various restrictions, and then on fine tuning, maintaining and adapting them to constant business changes, spend this time with your users. But spend it wisely - do not tell them what to do and what not, end of - explain the process and tell WHY doing something this or that way is important for the business, and the impact of not doing thing as business requires.
If you like spending your time on coding spend it rather on writting a report highlighting cases of non-compliance, so you can re-train specific users should they make a mistake
My 0.02£
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Hi All,
Just an update, with the below code added on "OnValidate Trigger" of No. Field we cannot create even the second purchase Order with same Item if the first Purchase order is not fully received and invoiced (and moved to achieve)
Should entering the same item be allowed in a different purchase document or not? Should it be possible
to enter the same item a second time in the same document if the first item has already been delivered?
there are lots of possible conditions to consider before asking for code.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