Start NAV Object in RTC with PowerShell

You might remember these blogposts:

I wanted to go a step further. Namely, I wanted to open/run a specific object from PowerShell.

Scenario’s

There are two scenario’s where I wanted to apply this:

  1. First of all the Test Toolkit. I’m sure we’re all using the testability framework, right? ;-). Well, automation of this framework makes sense. Automation with PowerShell makes sense as well. And running the Test codeunits with the CmdLet “Invoke-NAVCodeunit” is just not done, because the testability (and especially the test pages) needs to run in an environment WITH a User Interface. Invoke-NAVCodeunit is a background process, therefore not suitable to run Tests of the Testability framework. So I want to run a codeunit (For example the Test Runner) like I would do a Run of a codeunit in C/SIDE.
  2. In a demo scenario, I usually import objects and run a codeunit to import data into tables. I wanted to automate all: import objects, run codeunit AND show the data in the table that I just created. In this case, I wanted to run a table like I would run it in C/SIDE.

In other words, I would like to create a function like:

Start-NAVApplicationObjectInWindowsClient

That says it all, doesn’t it? 🙂 I didn’t care too much on mandatory parameters and such .. but I tried to create a function that also works in a Multitenant environment. Here is how it looks:

function Start-NAVApplicationObjectInWindowsClient
{
    [cmdletbinding()]
    param(
        [string]$ServerName=[net.dns]::Gethostname(), 
        [int]$Port=7046, 
        [String]$ServerInstance, 
        [String]$Companyname, 
        [string]$Tenant='default',
        [ValidateSet('Table','Page','Report','Codeunit','Query','XMLPort')]
        [String]$ObjectType,
        [int]$ObjectID
         )

    $ConnectionString = "DynamicsNAV://$Servername" + ":$Port/$ServerInstance/$Companyname/Run$ObjectType"+"?$ObjectType=$ObjectID&tenant=$tenant"
    Write-Verbose "Connectionstring: $ConnectionString ..."
    Start-Process $ConnectionString
}

There are only a few tricks that I would like to mention:

  • In my parameters, I’m using the “ValidateSet” attribute to provide a predefined set of values for “ObjectType” variable – which makes a lot of sense, obviously 😉
  • I couldn’t find anywhere how to provide both tenant and objectid in the URL. I checked MSDN and tried to search online, but nowhere. The problem is, you can provide the tenant with a “?” in the URL, like:

    DynamicsNAV://WIN-K5JLU49T31O:7046/DynamicsNAV90/CRONUS BELGIË NV/?tenant=default

    You can run a codeunit by also using that questionmark, like:

    DynamicsNAV://WIN-K5JLU49T31O:7046/DynamicsNAV90/CRONUS BELGIË NV/RunCodeunit?Codeunit=50000

    But how to combine the two? How to run a codeunit in a company of a specific tenant?? Apparently, the solution was quite simple: it’s just a matter of combining the two with an ampersand (&), like:

    DynamicsNAV://WIN-K5JLU49T31O:7046/DynamicsNAV90/CRONUS BELGIË NV/RunCodeunit?Codeunit=50000&tenant=default

Here are a few examples on how you can run the function.

Start-NAVApplicationObjectInWindowsClient `
    -ServerInstance DynamicsNAV90 `
    -ObjectType Codeunit `
    -ObjectID 50000 `
    -Verbose

Or with tenant:

Start-NAVApplicationObjectInWindowsClient `
    -ServerName ([net.dns]::GetHostName()) `
    -ServerInstance DynamicsNAV90 `
    -Tenant MyTenantID `
    -ObjectType Page `
    -ObjectID 23

Enjoy!

5.00 avg. rating (98% score) - 4 votes

Permanent link to this article: https://www.waldo.be/2015/07/09/start-nav-object-in-rtc-with-powershell/

1 comment

5 pings

  1. Microsoft Dynamics NAV
    Comprehensive Dynamics NAV adjudication that will appreciate the way you work and augment your finance conduct. Most info, http://crmwebx.com/

  1. […] Continue reading » […]

  2. […] « Start NAV Object in RTC with PowerShell […]

Leave a Reply to arvinderrehal Cancel reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.