@@ -8,7 +8,7 @@ Import-Module $PSScriptRoot\EnlistmentHelperFunctions.psm1
88function Invoke-ContosoDemoTool () {
99 param (
1010 [string ]$ContainerName ,
11- [string ]$CompanyName = (Get-NavDefaultCompanyName - ContainerName $ContainerName ),
11+ [string ]$CompanyName = (Get-TestCompanyName ),
1212 [switch ]$SetupData
1313 )
1414 Write-Host " Initializing company in container $ContainerName "
@@ -26,24 +26,13 @@ function Invoke-ContosoDemoTool() {
2626 Invoke-NavContainerCodeunit - CodeunitId 5691 - containerName $ContainerName - CompanyName $CompanyName
2727}
2828
29- function Get-NavDefaultCompanyName
30- {
31- param (
32- [string ]$ContainerName
33- )
34- # Log all companies in the container
35- $companies = Get-CompanyInBcContainer - containerName $ContainerName
36- $companies | Foreach-Object { Write-Host " Company: $ ( $_.CompanyName ) " }
37-
38- # Look for the Cronus company
39- $cronusCompany = $companies | Where-Object { $_.CompanyName -match " CRONUS" } | Select-Object - First 1
40- if ($cronusCompany ) {
41- Write-Host " Using company $ ( $cronusCompany.CompanyName ) for demo data generation"
42- return $cronusCompany.CompanyName
29+ function Get-TestCompanyName () {
30+ $companyName = Get-ALGoSetting - Key " companyName"
31+ if ([string ]::IsNullOrEmpty($companyName )) {
32+ return " CRONUS International Ltd." # Fallback in case no company name is specified in settings
33+ } else {
34+ return $companyName
4335 }
44-
45- # If no Cronus company is found, thow
46- throw " No Cronus company found in container $ContainerName .."
4736}
4837
4938function Invoke-DemoDataGeneration
@@ -70,6 +59,27 @@ function Invoke-DemoDataGeneration
7059
7160}
7261
62+ function New-TestCompany () {
63+ param (
64+ [Parameter (Mandatory = $true )]
65+ [string ]$ContainerName ,
66+ [Parameter (Mandatory = $true )]
67+ [string ]$CompanyName ,
68+ [Parameter (Mandatory = $false )]
69+ [switch ]$EvaluationCompany
70+ )
71+
72+ # Delete existing companies in the container
73+ $existingCompanies = Get-CompanyInBcContainer - containerName $ContainerName
74+ foreach ($company in $existingCompanies ) {
75+ Write-Host " Deleting company $ ( $company.CompanyName ) in container $ContainerName "
76+ Remove-CompanyInBcContainer - containerName $ContainerName - companyName $company.CompanyName
77+ }
78+
79+ Write-Host " Creating new test company in container $ContainerName "
80+ New-CompanyInBcContainer - containerName $ContainerName - companyName $CompanyName - evaluationCompany:$EvaluationCompany
81+ }
82+
7383# Reinstall all the uninstalled apps in the container
7484# This is needed to ensure that the various Demo Data apps are installed in the container when we generate demo data
7585$allUninstalledApps = Get-BcContainerAppInfo - containerName $parameters.ContainerName - tenantSpecificProperties - sort DependenciesFirst | Where-Object { $_.IsInstalled -eq $false }
@@ -88,4 +98,13 @@ foreach ($app in (Get-BcContainerAppInfo -containerName $ContainerName -tenantSp
8898 Write-Host " App: $ ( $app.Name ) ($ ( $app.Version ) ) - Scope: $ ( $app.Scope ) - $ ( $app.IsInstalled ) / $ ( $app.IsPublished ) "
8999}
90100
101+ $testType = Get-ALGoSetting - Key " testType"
102+ if ($testType -eq " Uncategorized" ) {
103+ Write-Host " Creating evaluation test company"
104+ New-TestCompany - ContainerName $parameters.ContainerName - CompanyName (Get-TestCompanyName ) - EvaluationCompany
105+ } else {
106+ Write-Host " Creating standard test company"
107+ New-TestCompany - ContainerName $parameters.ContainerName - CompanyName (Get-TestCompanyName )
108+ }
109+
91110Invoke-DemoDataGeneration - ContainerName $parameters.ContainerName - TestType (Get-ALGoSetting - Key " testType" )
0 commit comments