Rename Item code by using Codeunit

abnainas
Member Posts: 174
Dear All,
I'm tring to rename the item code for 3700 items, So I made a codeunit to do the following:
Do you have another code to do the same result.
I'm tring to rename the item code for 3700 items, So I made a codeunit to do the following:
OnRun() itemrec.FIND('-'); REPEAT itemrec.INIT; itemrec.RENAME(itemrec."No." + 'V'); UNTIL itemrec.NEXT = 0;
Do you have another code to do the same result.
Ahmad Bani Naser
Dynamics NAV Developer
Dynamics NAV Developer
0
Comments
-
Dear All,
When I'm used the following Code.... Nothing Happend.OnRun() itemrec.FIND('-'); REPEAT itemrec.INIT; itemrec.RENAME('V' + itemrec."No."); UNTIL itemrec.NEXT = 0;
Please note that Item Code is a numbers.
Please adviseAhmad Bani Naser
Dynamics NAV Developer0 -
OnRun() itemrec.REST; IF itemrec.FIND('-') THEN REPEAT itemrec.RENAME('V' + itemrec."No."); UNTIL itemrec.NEXT = 0;
what about that?
Also as far as i know, the Primary key in item table is No with type Code.Enabled Field No. Field Name Data Type Length
Yes 1 No. Code 20-Mihail- [MCTS]0 -
Problem is that if your item numbers are digits only, then adding V in front of any number moves your current position to the end of the table.
items before rename :
01
02
03
renaming 01 to V01 will give you
02
03
V01
So if ItemRec.No was '01', and ItemRec.No is 'V01' after rename, ItemRec.NEXT cannot find any more records.
try this:itemrec.REST; itemrec.ASCENDING(FALSE); itemrec.SETRANGE("No.", <first current item no here>, <last current item no here>); IF itemrec.FIND('+') THEN REPEAT itemrec.RENAME('V' + itemrec."No."); UNTIL itemrec.NEXT(-1) = 0;
or thisitemrec.REST; itemrec.SETRANGE("No.", <first current item no here>, <last current item no here>); IF itemrec.FIND('-') THEN REPEAT itemrec2 := itemrec; itemrec.RENAME('V' + itemrec."No."); itemrec := itemrec2; UNTIL itemrec.NEXT = 0;
Don't forget set proper filters on itemrec."no."
Regards,
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
it's worked,
thanks alotAhmad Bani Naser
Dynamics NAV Developer0 -
[Topic moved from 'NAV 2009' forum to 'NAV/Navision' forum]Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!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