No, there is not a dotnet add-in, just using dotnet in C/AL.
I have made updates to this tool. Read about it here.
There is an old version of a renumbering tool on this blog. It works in the classic client but who uses the classic client any more ?
I wanted to upgrade this tool to NAV 2015 (and NAV 2013 R2). There where a few issues that I needed to handle. First; how to upload a large object file to the server, how to read through millions of lines to find what I was looking for, how to replace string in all these lines without having to wait for days.
That is what I did. One Table and One Page. The code is all in the Table, not the ideal setup but I preferred fewer objects over prettier design. On the other hand this it not that big of an object so every developer should find the way through the code in there.
I have been sharing objects on this blog and have also started to share and sell objects on Objects4NAV.com. These objects are all in the range from 50.000 to 99.999. This tool will make it so much easier to import these objects into the database. Just download the renumbering tool and manually install it into the database and use the tool from there.
A little spoiler, I just used this tool on an object file with just under four million lines and needed to renumber 116 objects. The tool completed this in two minutes and forty two seconds.
So, how does it work?
The page has only three columns. Source object type, source object id and the new destination id. If you leave the destination id blank the line will be ignored. If you need to renumber an object to a number that already exists in the database start by renumber the old object before reusing the object id.
In here we have five functions:
- Read Object Lines will populate the renumbering lines from an object file.
- Suggest IDs will look for available id by searching the license permission and will update the renumbering lines.
- Write to Excel will export the renumbering lines to an Excel worksheet.
- Read from Excel will import the same format from an Excel worksheet.
- Update Object File will apply the object changes in the renumbering lines to an object file and will save a new object file.
If you have this tool in the customer database then you can import the object file you want to add to the database, get a suggestion for new ids, export a new object file and import that one into the database. This will only take a few seconds.
Lets take a closer look at the code. Perhaps that will help you in some of your ongoing task or in the future.
The first thing that the tool does is to upload the object file to the server temporary folder. In NAV we have a function for this purpose but that one can only handle a limited amount of data. A four million lines of code will not be uploaded with the standard method so I had to create another one.
The magic word here is streaming. This code will take 4KB of data in each portion and upload to the server. It will repeat until done and I don’t think you will find a useful NAV file that will not be uploaded with this code.
Once the file is on the server the tool loads the whole file into memory.
An array of string is used to store all the object lines.
This is the starting point. From this point I can loop through all the lines and do what ever I want. However, doing that line by line will take forever so I have applied a few tricks on the way.
When the tool is loading an object file into the renumbering lines it will use the dotnet string function split to break the line into smaller bits. When the tool finds an object it will search the string array for the end of that object before continuing and can therefore skip all lines except the ones needed to build the renumbering lines.
When renumbering, instead of applying each renumbering line to every code line, the tool combines five thousand lines into one dotnet string variable and uses the dotnet function replace to update the code. After each chunk of code is updated it is downloaded from the server to the client side and written to the local file system.
Well, what are you waiting for. Download the renumbering tool and start using it today.
22 Replies to “New renumbering tool with DotNet power”
I like the idea of what you are doing but I’m getting a problem with your objects.
When I attempt to load the objects, the LoadObjectDataIntoSetup function fails when it gets to:
SplitStringArray := ObjectData.Split(SplitCharArray)
with the message “A call to Microsoft.Dynamics.Nav.Runtime.NavText.Split failed with this message: The type of one or more arguments does not match the methods parameter type.”
The debugger shows the SplitCharArray is initialised as an array of System.Char and ObjectData has a Split method that will accept this as a parameter. So I am missing something here but I am not sure what. I’ve tried tinkering with various bits but it hasn’t made any difference.
Please can you give some guidance? Thanks.
Just re-reading it, why is the message saying “Microsoft.Dynamics.Nav.Runtime.NavText.Split” when ObjectData is defined as a “System.String”? Is that the problem?
Perhaps you can send me a link to the object file and the excel document with the renumbering data ?
You said in the original post that you wanted to use this in 2013 R2. However, it turns out that it is not backwardly compatible. Although the ObjectData variable is declared as System.String, it is actually treated as a NavText when it runs in 2013 R2 and that does not appear to support the split method that you are using. I’ve imported your objects into 2015 and they load the file now.
Another case of Microsoft “improving” the user experience.
Then, let’s hope everyone can use the 2015 version or create a patched version for 2013 R2. I don’t thing I will take the time to take this back to 2013 R2. Thank you for your input.
I just wanna say that I’ve used this today without any issues in NAV 2013 R2, so maybe it started working with some hotfix
Thank you Johan.
Great tool. Really helped me a lot. I’ll share with you the slight modifications on code for it to work for me.
I used it today and it worked fine. Can you add Field renumbering as well?
I believe I can Luc, just a question of time I guess. Are you talking about a field number change across all tables ?
Did you improve your code to renumber a field (imagine that you need to renumber a field from 50000 to 190000 and that field is already used in a codeunit)?
Does your code work with NAV 2016?
Thank you for your post and code and keep the good work, I will test and use your tool now.
Hi Lúri, I did not upgrade the renumbering tool to work with field numbers nor Ids. You can import the objects into NAV 2016 and it should work.
Thank you for your fast answer.
And keep the good work.
Hi Gunnar, I have gone through your blog and have seen people are using is successfully.However I am little unsure how to use this tool. I have downloaded the fob – one table (Object Renumber) one page (Object Renumbering) .Is this enough ? or some other objects are also there for this tool ?
I need to renumber a set of objects in NAV 2016 . Can you help me out with the steps.
Thanks for the tool. I have found a little problem in the code which corrupts previously renumbered ID’s if you have objects with source id which begin with the same digit sequence. The fix for that is to change lines:
OldValue := STRSUBSTNO(‘%1 %2’,RenumberingSetup.”Source Type”,RenumberingSetup.”Source ID”);
NewValue := STRSUBSTNO(‘%1 %2’,RenumberingSetup.”Source Type”,RenumberingSetup.”Destination ID”);
OldValue := STRSUBSTNO(‘%1 %2 ‘,RenumberingSetup.”Source Type”,RenumberingSetup.”Source ID”);
NewValue := STRSUBSTNO(‘%1 %2 ‘,RenumberingSetup.”Source Type”,RenumberingSetup.”Destination ID”);
the change is additional space at the end of ‘%1 %2 ‘
Thank you very much. I am putting the source on GitHub.com/gunnargestsson and will make sure to include this update.