Invoke-NAVCodeunit

Invokes the specified codeunit with the specified parameters.

Syntax

Invoke-NAVCodeunit
      [-Tenant <TenantId>]
      [-CompanyName <String>]
      -CodeunitId <Int32>
      [-MethodName <String>]
      [-Argument <String>]
      [-Language <LanguageSetting>]
      [-TimeZone <InvokeCodeunitTimeZone>]
      [-RetryMode <RetryMode>]
      [-NetworkTimeout <TimeSpan>]
      [-MaxRetries <Int32>]
      [-DelayBetweenRetries <TimeSpan>]
      [-ServerInstance] <String>
      [-Force]
      [-ProgressAction <ActionPreference>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Description

You must specify a codeunit and a Business Central 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.

Examples

EXAMPLE 1

Invoke-NAVCodeunit -ServerInstance BC -CompanyName 'CRONUS International Ltd.' -CodeunitId 100000 -Language 'da-DK'

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 Business Central Server instance BC.

EXAMPLE 2

Invoke-NAVCodeunit -ServerInstance BC -Tenant Tenant1 -CompanyName MyCompanyName -CodeunitId 2

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

EXAMPLE 3

Invoke-NAVCodeunit -ServerInstance BC -Tenant Tenant1 -CompanyName MyCompanyName -CodeunitId 104048 -MethodName "UpgradeStep2"

The example runs the UpgradeStep2 method in codeunit 104048, which is part of the Upgrade Toolkit for Business Central.

Parameters

-Argument

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

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-CodeunitId

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.

Type:Int32
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-CompanyName

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 Business Central Server instance.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DelayBetweenRetries

Specifies the delay between retries.

Type:TimeSpan
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Force

Forces the command to run without asking for user confirmation.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Language

Specifies the language that the codeunit will run in. You must specify a valid culture name for a language in Business Central, such as en-US or da-DK. If the specified language does not exist on the Business Central Server instance, the codeunit will run in en-US.

Type:LanguageSetting
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-MaxRetries

Specifies the maximum number of retries for the operation in case of failure.

Type:Int32
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-MethodName

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

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-NetworkTimeout

Specifies the network timeout of the operation.

Type:TimeSpan
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ProgressAction

A common PowerShell parameter that determines how PowerShell responds to progress updates generated by a script, cmdlet, or provider. Learn more.

Type:ActionPreference
Aliases:proga
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-RetryMode

Specifies the retry mode when the service instance is not available.

Possible values: Fixed, Exponential

Type:RetryMode
Accepted values:Fixed, Exponential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ServerInstance

Specifies the name of a Business Central Server instance, for example, BC or myinstance. You can specify either the full name of an instance, such as MicrosoftDynamicsNavServer$myinstance or the short name such as myinstance.

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Tenant

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.

Type:TenantId
Aliases:Id
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-TimeZone

Specifies the time zone that the invoked codeunit will use for date calculations. You can set the parameter to the following values:

Utc - Uses Universal Coordinated Time (UTC) as the time zone. This is the default value. If you do not set this parameter, then UTC is used.

ClientTimezone - Uses the time zone that is configured for the computer on which the cmdlet is run.

TenantTimezone - Uses the default time zone that is configured for the tenant. The tenant's time zone is configured when the tenant is mounted on the Business Central Server instance. This is only relevant when the Business Central Server instance is configured as a multitenant instance.

ServicesDefaultTimeZone - Uses the default time zone that is configured web services on the Business Central Server instance.

Type:InvokeCodeunitTimeZone
Accepted values:Utc, ClientTimeZone, TenantTimeZone, ServicesDefaultTimeZone
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False