Invoke-NAVCodeunit

Invoke-NAVCodeunit

Invokes the specified codeunit with the specified parameters.

Syntax

Parameter Set: __AllParameterSets
Invoke-NAVCodeunit [-ServerInstance] <String> -CodeunitId <Int32> [-Argument <String> ] [-CompanyName <String> ] [-Force] [-Language <LanguageSetting> ] [-MethodName <String> ] [-Tenant <TenantId> ] [ <CommonParameters>]

Detailed Description

You must specify a codeunit and a Microsoft Dynamics NAV Server instance. Optionally, you can specify other parameters.

By default, the OnRun trigger is called, but you can specify a different method name and pass it an optional string argument.

You can run the codeunit within the scope of a company, a tenant, or both. Optionally, you can specify the language that you want to use when you invoke the codeunit. Return values are ignored.

Parameters

-Argument<String>

Specifies a string argument that is passed to the specified method on the codeunit.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-CodeunitId<Int32>

Specifies the ID of the codeunit that you want to invoke.

The Invoke-NAVCodeunit cmdlet calls the OnRun trigger in the specified codeunit. You can call another method if you specify it in the MethodName parameter.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-CompanyName<String>

Specifies the name of the company that you want to run the codeunit in.

If you do not set this parameter, the codeunit will run in the default company for the Microsoft Dynamics NAV Server instance.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-Force

Forces the command to run without asking for user confirmation.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Language<LanguageSetting>

Specifies the language that the codeunit will run in. You must specify a valid culture name for a language in Microsoft Dynamics NAV, such as en-US or da-DK.

If the specified language does not exist on the Microsoft Dynamics NAV Server instance, the codeunit will run in en-US.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-MethodName<String>

Specifies the method that will be called. If no method is specified, the OnRun trigger is called.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-ServerInstance<String>

Specifies the name of a Microsoft Dynamics NAV Server instance. The default instance name is DynamicsNAV71. You can specify either the full name of an instance such as MicrosoftDynamicsNavServer$myinstance or the short name such as myinstance.

Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByValue, ByPropertyName)

Accept Wildcard Characters?

false

-Tenant<TenantId>

Specifies the ID of the tenant that you want to invoke the codeunit in, such as Tenant1. This parameter is required unless the specified service instance is not configured to run multiple tenants.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters.

Examples

-------------------------- EXAMPLE 1 --------------------------

Description

-----------

This example invokes codeunit 100000 and calls the OnRun trigger because no other method is specified. The code runs with Danish language settings in the CRONUS International Ltd. company in the Microsoft Dynamics NAV Server instance DynamicsNAV71.

PS C:\> Invoke-NAVCodeunit -ServerInstance DynamicsNAV71 -CompanyName 'CRONUS International Ltd.' -CodeunitId 100000 -Language 'da-DK'

-------------------------- EXAMPLE 2 --------------------------

Description

-----------

This example shows how you can use the Invoke-NAVCodeunit cmdlet to initialize a company in a tenant database.

The example invokes codeunit 2, which initializes the MyCompanyName company.

PS C:\> Invoke-NAVCodeunit -ServerInstance DynamicsNAV71 -Tenant Tenant1 -CompanyName MyCompanyName -CodeunitId 2

-------------------------- EXAMPLE 3 --------------------------

Description

-----------

This example shows how you can use the Invoke-NAVCodeunit cmdlet to run a specific method in a codeunit.

The example runs the UpgradeStep2 method in codeunit 104048, which is part of the Upgrade Toolkit for Microsoft Dynamics NAV 2013 R2.

PS C:\> Invoke-NAVCodeunit -ServerInstance DynamicsNAV71 -Tenant Tenant1 -CompanyName MyCompanyName -CodeunitId 104048 -MethodName "UpgradeStep2"