Renumbering NAV Object Ids


A few weeks ago, I decided that now was the time to convert my BingMaps extension into a “real” extension.

A Dynamics 365 for Financials App, which I could add to AppSource.

In order to do that, I need to place my objects in my newly assigned object range in the 70 mio range and even though my BingMaps extension was fairly small and in the end, it would be easiest to just walk through all objects and renumber them manually, I decided to search for a renumber tool.

Tools out “there”

I found a few tools, which would be able to renumber objects and references, but I also needed to renumber references in language .txt files, in Web Services declaration .xml files, in .delta files and last but not least in .al files (the new developer experience:-))

Beside this, all the tools I found was solutions built in NAV, meaning that I would have to create a NAV instance, import objects and then use that to do the renumbering. Somewhat automated, but still a manual process.

I wanted a command, which I could call and voila – here you are (sorry if there already is another tool like this, I didn’t see).

Approach

I decided to make my own tool. A tool, written in C#. Available as a command line program and as a PowerShell CmdLet. A tool which could do exactly what I need for my extensions, but would be flexible enough to be used for other people in my situation.

Yesterday, I told Waldo about this and he immediately tweeted about it and then I had to go public a little earlier than expected…

The tool is on GitHub to allow other people to download, use and contribute to the tool: https://github.com/NAVDEMO/RenumberNavObjectIds

Clone the project and open in Visual Studio 2015. Build and you are off to a good start.

Try to renumber the BingMaps sample on the Azure Gallery Image

If you want to try it out, the easiest way is the following.

  • Deploy an Azure Demo instance using https://aka.ms/navdemodeploy
  • Run C:\DEMO\Install Visual Studio 2015 Trial.ps1 inside the Virtual Machine using PowerShell.
  • Navigate to https://github.com/NAVDEMO/RenumberNavObjectIds inside the Virtual Machine.
    • Select Clone and Open in Desktop (download GitHub for Windows)
    • Place the solution in the default location.
    • Open the Solution in Visual Studio and Build it.
  • Run the following PowerShell Script in PowerShell ISE
import-module "C:\Users\vmadmin\Documents\GitHub\RenumberNavObjectIds\RenumberObjectIds\bin\Debug\RenumberObjectIds.dll"
$RenumberList = @{}
0..49 | % { $RenumberList += @{ (52000+$_) = (80000+$_) } }
Renumber-NavObjectIds -SourceFolder "c:\DEMO\BingMaps\sources" `
                      -DestinationFolder "c:\DEMO\BingMaps\newsources" `
                      -RenumberList $RenumberList `
                      -Verbose
  • Install WinMerge on the Virtual Machine and Compare the content of the two directories

winmerge-1

  • Investigate the two directories. Note, that the function also renumbers the file names, which makes comparison a bit harder.

winmerge-2

  • You can remove the object ids in the filename, or you can run three commands in cmd (in C:\DEMO\BingMaps\Sources), which will cause the object ids in the filename to be different (ex. 152000 instead of 52000) and thus not renumbered
rename COD*.* CO1*.*
rename PAG*.* PA1*.*
rename TAB*.* TA1*.*
  • Re-run the PowerShell to renumber the objects
  • Re-fresh the compare in WinMerge and you should see

winmerge-5

  • Double-click a few of the objects to see what has been renumbered

winmerge-6 winmerge-7

But what about…???

It handles individual (split) object files or a combined object file exported from NAV. I cannot say, that it has been tested on a large number of different objects – so there might be issues.

If there are, then please report them here: https://github.com/NAVDEMO/RenumberNavObjectIds/issues and/or create a suggested fix and submit a Pull Request.

What files are handled, and what happens?

Basically the tool will enumerate all files in the SourceFolder and copy them to the DestinationFolder. Based on the file type, certain actions are taken:

.delta files or .txt files, where the first word is OBJECT

are treated as OBJECT definitions. Read line by line. Using text search to replace occurrences of object ids to new object ids and indentation is adjusted if necessary.

Special notes:

  • An object id is only matched if it is NOT preceded or superseded by a numeric character. (152000 does not match 52000, nor does 520001)
  • An object id is not matched if it is inside a double-quotes or single-quotes.
  • PAGE.RUN(52000) will be matched, but so will Price := 52000 – this could potentially be problematic:-)

.txt files, where the first word is NOT OBJECT

are treated as language translation files and all occurrences of object ids in the files preceded by characters: N, C, Q, F or G and superseded by a minus sign will be renumbered. If the translated text contains “N52000-“, then this will also be renumbered. I don’t think that this will happen.

.xml files

are treated like Permissions or Web Services definitions (for extensions packages) and any occurrence of <ObjectID>52000</ObjectID> will be renumbered.

.al files

are treated as new development environment files and renumered as normal object definition files.

.json files

are treated as the app.json file and occurrences of StartupObjectId: 52000 is renumbered.

Commandline program

There is also a Commandline version of the program (if you are not into PowerShell).

commandline

You can specify a range or an objectidfile. If you specify both, then the ObjectIdfile will be written using the range and you can extend the objectidfile with more objects.

The commandline version also supports a reverse mechanism to renumber (and copy) from destination to source.

What NOT to do!

Please do NOT use the renumber tool to renumber objects with ID = 1 or 2 or other values which might be frequent in the programming language – based on the explanation above, this will cause problems.

What to do!

Try this on your objects, report issues on Github, help fix issues and create pull requests.

 

Enjoy

Freddy Kristiansen
Technical Evangelist

Comments (0)

Skip to main content