PowerShell: Generate Symbol Reference für AL (mit GUI)
Verfasst: 23. Januar 2018 18:36
Das manuelle Generieren von Symbolen für AL ist ja bislang nur über die Kommandozeile möglich (Neuer Parameter für finsql.exe command=generatesymbolreference) .
[Nachtrag]: Das Cmdlet Compile-NavApplicationObject -GenerateSymbolReference -Recompile ist nun auch verfügbar, um diese bequemer zu erzeugen, Filter auf einzelne Objekte z.B. so setzen -Filter 'Type=Table;ID=50093'
Running C/SIDE and AL Side-by-Side
Mit diesem Skript mit Eingabefenster ist es deutlich einfacher, die Kommandozeile wird damit erzeugt und ausgeführt. Der Objektfilter ist dabei optional. Vorher nicht vergessen, das neue Feld Enable loading application symbol references at server startup
auf dem Server zu aktivieren und den Dienst danach neu zu starten.
Im Programmverzeichnis liegt nach Beendigung diese Datei, die aber leider kein Indiz für eine korrekte Erzeugung ist, siehe hier .
Der Beispielcode hier für das Fenster enthält übrigens einen Fehler (Script bzw. Global Scope der $x-Variablen fehlen), das ist im Skript natürlich korrigiert .
[Edit 11.02.18] Für noch mehr Komfort mit einer automatisch generierten Datenbankliste siehe diese Variante hier.
Für Business Central-Programmpfad (hier für Version 13 = Programmpfad …\130\…, für Folgeversionen entsprechend ändern)
Für NAV-Programmpfad
Tags: generatesymbolreference
[Nachtrag]: Das Cmdlet Compile-NavApplicationObject -GenerateSymbolReference -Recompile ist nun auch verfügbar, um diese bequemer zu erzeugen, Filter auf einzelne Objekte z.B. so setzen -Filter 'Type=Table;ID=50093'
Running C/SIDE and AL Side-by-Side
Mit diesem Skript mit Eingabefenster ist es deutlich einfacher, die Kommandozeile wird damit erzeugt und ausgeführt. Der Objektfilter ist dabei optional. Vorher nicht vergessen, das neue Feld Enable loading application symbol references at server startup
auf dem Server zu aktivieren und den Dienst danach neu zu starten.
Im Programmverzeichnis liegt nach Beendigung diese Datei, die aber leider kein Indiz für eine korrekte Erzeugung ist, siehe hier .
Der Beispielcode hier für das Fenster enthält übrigens einen Fehler (Script bzw. Global Scope der $x-Variablen fehlen), das ist im Skript natürlich korrigiert .
[Edit 11.02.18] Für noch mehr Komfort mit einer automatisch generierten Datenbankliste siehe diese Variante hier.
Für Business Central-Programmpfad (hier für Version 13 = Programmpfad …\130\…, für Folgeversionen entsprechend ändern)
- Code:
function GenerateSymbolsBC
{
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
function GenerateSymbolsForDatabase
{
[CmdletBinding()]param (
[String]$Server,
[String]$Database,
[String]$ObjectFilter)
$NAVFolder = 'C:\Program Files (x86)\Microsoft Dynamics 365 Business Central\130\RoleTailored Client'
if ($ObjectFilter -ne '')
{$Command = """$NAVFolder\finsql.exe"" command=generatesymbolreference,servername=$Server,database=$Database,filter=$ObjectFilter"}
else
{$Command = """$NAVFolder\finsql.exe"" command=generatesymbolreference,servername=$Server,database=$Database"}
Write-host $Command
cmd /c $Command
}
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Generate Symbols"
$objForm.Size = New-Object System.Drawing.Size(300,300)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") {$script:x=$objTextBox.Text;$script:x2=$objTextBox2.Text;$script:x3=$objTextBox3.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,220)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$script:x=$objTextBox.Text;$script:x2=$objTextBox2.Text;$script:x3=$objTextBox3.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,220)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
#############
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Server"
$objForm.Controls.Add($objLabel)
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)
$objLabel2 = New-Object System.Windows.Forms.Label
$objLabel2.Location = New-Object System.Drawing.Size(10,65)
$objLabel2.Size = New-Object System.Drawing.Size(280,20)
$objLabel2.Text = "Database"
$objForm.Controls.Add($objLabel2)
$objTextBox2 = New-Object System.Windows.Forms.TextBox
$objTextBox2.Location = New-Object System.Drawing.Size(10,85)
$objTextBox2.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox2)
$objLabel3 = New-Object System.Windows.Forms.Label
$objLabel3.Location = New-Object System.Drawing.Size(10,105)
$objLabel3.Size = New-Object System.Drawing.Size(280,20)
$objLabel3.Text = "Object Filter"
$objForm.Controls.Add($objLabel3)
$objTextBox3 = New-Object System.Windows.Forms.TextBox
$objTextBox3.Location = New-Object System.Drawing.Size(10,125)
$objTextBox3.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox3)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
#Write-host "$x $x2 $x3"
if (($x -ne '') -and ($x2 -ne '') -and ($x3 -eq ''))
{GenerateSymbolsForDatabase -Server $x -Database $x2}
elseif (($x -ne '') -and ($x2 -ne '') -and ($x3 -ne ''))
{GenerateSymbolsForDatabase -Server $x -Database $x2 -ObjectFilter $x3}
else
{
[System.Windows.Forms.MessageBox]::Show("Please enter server and database. Object Filter is an option.")
Write-Error 'Please enter server and database. Object Filter is an option.'
}
}
GenerateSymbolsBC
Für NAV-Programmpfad
- Code:
function GenerateSymbolsNAV
{
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
function GenerateSymbolsForDatabase
{
[CmdletBinding()]param (
[String]$Server,
[String]$Database,
[String]$ObjectFilter)
$NAVFolder = 'C:\Program Files (x86)\Microsoft Dynamics NAV\110\RoleTailored Client'
if ($ObjectFilter -ne '')
{$Command = """$NAVFolder\finsql.exe"" command=generatesymbolreference,servername=$Server,database=$Database,filter=$ObjectFilter"}
else
{$Command = """$NAVFolder\finsql.exe"" command=generatesymbolreference,servername=$Server,database=$Database"}
Write-host $Command
cmd /c $Command
}
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Generate Symbols"
$objForm.Size = New-Object System.Drawing.Size(300,300)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") {$script:x=$objTextBox.Text;$script:x2=$objTextBox2.Text;$script:x3=$objTextBox3.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,220)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$script:x=$objTextBox.Text;$script:x2=$objTextBox2.Text;$script:x3=$objTextBox3.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,220)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
#############
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Server"
$objForm.Controls.Add($objLabel)
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)
$objLabel2 = New-Object System.Windows.Forms.Label
$objLabel2.Location = New-Object System.Drawing.Size(10,65)
$objLabel2.Size = New-Object System.Drawing.Size(280,20)
$objLabel2.Text = "Database"
$objForm.Controls.Add($objLabel2)
$objTextBox2 = New-Object System.Windows.Forms.TextBox
$objTextBox2.Location = New-Object System.Drawing.Size(10,85)
$objTextBox2.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox2)
$objLabel3 = New-Object System.Windows.Forms.Label
$objLabel3.Location = New-Object System.Drawing.Size(10,105)
$objLabel3.Size = New-Object System.Drawing.Size(280,20)
$objLabel3.Text = "Object Filter"
$objForm.Controls.Add($objLabel3)
$objTextBox3 = New-Object System.Windows.Forms.TextBox
$objTextBox3.Location = New-Object System.Drawing.Size(10,125)
$objTextBox3.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox3)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
#Write-host "$x $x2 $x3"
if (($x -ne '') -and ($x2 -ne '') -and ($x3 -eq ''))
{GenerateSymbolsForDatabase -Server $x -Database $x2}
elseif (($x -ne '') -and ($x2 -ne '') -and ($x3 -ne ''))
{GenerateSymbolsForDatabase -Server $x -Database $x2 -ObjectFilter $x3}
else
{
[System.Windows.Forms.MessageBox]::Show("Please enter server and database. Object Filter is an option.")
Write-Error 'Please enter server and database. Object Filter is an option.'
}
}
GenerateSymbolsNAV
Tags: generatesymbolreference