070914_0851_PowershellT1.pngI’ve been trying to get this out for a while now.. finally I was able to :-).

If you have been to one of the Directions (US or EMEA) or the last session of the Dutch Dynamics Community, you might have visited one of the session about the great new addition in NAV2015 (in fact, already in NAV2013 R2 CU9): the new PowerShell commandlets to merge Microsoft Dynamics NAV objects .. or its official name: RapidStart Upgrade – Code. If you have, you might have figured that “dealing with Versionlists” is something you’ll have to do yourself, as it’s really dependend on how you handle your versionlists – which might differ from partner to partner, product to product, case to case.. .

In Microsoft’s presentation, a PowerShell script was shown in PowerPoint .. and the moment I saw that script, I knew that was the solution on how we do versionlists in my company. So I took that script, changed it a little bit (I didn’t like working with the mergeinfo, as you don’t always have this object, neither it is convenient to test…) .. and now I have a prefectly working script that I have used many times in my company, and – for us – works like a charm!

Here it is:

function Merge-NAVVersionList
{
  param (
  [String]$OriginalVersionList,
  [String]$ModifiedVersionList,
  [String]$TargetVersionList,
  [String[]]$Versionprefix
)
  $allVersions = @() + $OriginalVersionList.Split(',')
  $allversions += $ModifiedVersionList.Split(',')
  $allversions += $TargetVersionList.Split(',')
  $mergedversions = @()
  foreach ($prefix in $Versionprefix)
  {
    #add the "highest" version that starts with the prefix
    $mergedversions += $allVersions | where { $_.StartsWith($prefix) } | Sort | select -last 1
    # remove all prefixed versions
    $allversions = $allVersions.Where({ !$_.StartsWith($prefix) })
  }
  # return a ,-delimited string consiting of the "hightest" prefixed versions and any other non-prefixed versions
  $mergedversions += $allVersions
  $mergedVersions -join ','
}

It’s a simple concept. Let’s suppose I’m the script. This is how I would handle your versionlist:

  • Put all the versiontags into an array, so I can sort it, filter it, .. .
  • Give me all the prefixes of which you want the highest tag of
  • For each prefix you give me, I’ll
    • filter the array on that prefix
    • Sort it
    • Get the highest number
    • Put that in a separate variable
    • Remove everything from that prefix in the original aray
  • In the end, I add everything that’s left in my array
  • There you go, you have your merged VersionList

This is a script that even cleans up your VersionList as you can re-sort it, having all your productversions in the right order for all objects. I really love it!

Here is an example on how to use it:

$MyVersionprefix =  'NAVW1', 'NAVBE', 'I'
$OrigVersionlist = 'NAVW17.10.00.37563,NAVBE7.10.00.37563'
$ModVersionList = 'NAVW17.10.00.37563,NAVBE7.10.00.37563,I7.4,M22344,M65877'
$TgtVersionList = 'NAVW18.00,NAVBE8.00'
Merge-NAVVersionList `
	-OriginalVersionList $OrigVersionlist `
	-ModifiedVersionList $ModVersionList `
	-TargetVersionList $TgtVersionList `
	-Versionprefix $MyVersionprefix

So, just provide the original, modified and target versionlist, and add the prefixes you want in your resulting versionlist. The result of the code above would be: ‘NAVW18.00,NAVBE8.00,I7.4,M22344,M65877′

Just for your reference, an extract from my main merge-script, where I use this very same function:


Thanks to Microsoft for getting me into the right direction! This script has saved me loads of time!