Automating The nCode Reference Data Download

nCode uses reference data published by Canada Post to match and correct your Canadian mailing addresses. Getting the latest monthly reference data update is easy. We email our customers with links to download the new file each month. You just click the link and the file is downloaded right to your PC. Installing the database update is as simple as copying this file into your nCode directory.

As simple as this process is, some nCode users prefer to use a fully automated reference data update process.

We have an automated mechanism for distributing reference data files. If you’d like to know more about it, you can download a guide from your My Downloads page.

With the automated download process, you can use your batch scheduler to look for and download reference data updates when they are published each month.

Here is an example of a PowerShell script for Windows that downloads and installs the nCode PCAD reference data file whenever it changes:


## This is a PowerShell script to perform an automated download of the
## nCode address reference data file: NCODEREF.DAT or NCODEPOC.DAT.
##
## The script is designed to use the automated download mechanism and 
## requires a special URL that you must get from support@novamg.com in 
## order to access the file.  
##
## The script checks to see if the current reference data file is newer 
## than the one which is installed on your system.  If it is, the new
## file is downloaded and placed in the default install directory.
## This script assumes the default data installation folder.  You can 
## change it if you've used a non-default location.

$RC = 0

## Declare the download locations of the reference data files...
## NOTE: You need to replace the values ###### with your personalized download code
##       which is available to registered users from support@novamg.com.
$RefDateUrl = "https://www.novamg.com/downloads/unattended.aspx?date=######"
$RefFileUrl = "https://www.novamg.com/downloads/unattended.aspx?voucher=######"

## Declare where the reference data lives...
$nCodeDataFolder = [System.Environment]::GetFolderPath("CommonApplicationdata") + "\Nova Marketing Group\nCode\"
$RefDateFile = $nCodeDataFolder + "REFDATE.TXT"
## For NCODEPOC.DAT download use the following instead
## $RefFile = $nCodeDataFolder + "NCODEPOC.DAT"
$RefFile = $nCodeDataFolder + "NCODEREF.DAT"

## Download the (temporary) reference data last updated date information file...
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($RefDateUrl, $RefDateFile)

## Determine the date of the installed reference data file...
if (Test-Path $RefFile)
{
    $RefFileDate = (Get-ChildItem $RefFile).LastWriteTime.toString("yyyy-MM-dd")
}
else
{
    $RefFileDate = ([datetime]::Today).AddYears(-20).toString("yyyy-MM-dd")
}

## Extract the date of the current production reference data from the temporary file...
$CurRefDate = (Get-Content $RefDateFile)

## Is newer reference data available?
if ($RefFileDate -lt $CurRefDate)
{
    ## Download the new file...
    $wc.DownloadFile($RefFileUrl, $RefFile)
    $RC = 2
}
else
{
    ## Nothing to do.
    $RC = 1
}

## Remove the temporary reference date information file...
del $RefDateFile

exit $RC

Feel free to use this PowerShell script or make changes to it to suit you environment. Please note that this sample script is provided “as-is” for illustration purposes only. If you would like to use this PowerShell script but are new to PowerShell, we recommend this blog by Scott Hanselman which provides step-by-step directions for handling the code-signing intricacies of PowerShell. We’d also recommend this blog which has a great tip for handling a particularly vexing PowerShell script signing error.

Adding a script like this to your Windows Task Scheduler is easy. Just create a daily task that executes the following program with these command line arguments (adjusting as necessary for the location of your Windows folder and your PowerShell script file):

Program: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 
Command Line: -NoProfile -NonInteractive -command ". c:\scripts\nCodeDataDownload.ps1; exit $LASTEXITCODE"

If you’d like to know more about our automated reference data download service, please contact us at support@novamg.com. We’ll be glad to help you.

Post a Reply