How do i throw an error message for the backend powershell script written for the combo box entered value and link it.
Scenario is - if user enters wrong value, i need to tell him that he has entered the wrong value and he needs to try again before the installation starts.
Backend power shell script validation is there for which i need to display the error message in the UI - How do i do that?
# Block for declaring the script parameters.
Param()
# Your code goes here.
# the path to your .json file
$jsonfile = 'C:\ProgramData\MyApp\Config\appsettings.json'
# convert the JSON data to a PowerShell object
$json = Get-Content $jsonfile | Out-String | ConvertFrom-Json
#fetch the SiteName from combobox
$SiteName = AI_GetMsiProperty COMBOBOX_1_PROP
if($SiteNamer.length -gt 12)
{
$SiteNameValidation =$false
}
elseif( $SiteNamer.Length -lt 7)
{
$SiteNameValidation =$false
}
elseif( $SiteName -match '[^a-zA-Z0-9]')
{
$SiteNameValidation =$false
}
else
{
$SiteNameValidation =$true
}
#fetch the EquipmentPhysicalIdentifier from combobox
$EquipmentPhysicalIdentifier = AI_GetMsiProperty COMBOBOX_2_PROP
if( $EquipmentPhysicalIdentifier -match '[^a-zA-Z0-9]')
{
throw "$WeirSerialNumber contains a special character"
}
if (-NOT ( $EquipmentPhysicalIdentifier.StartsWith("Weir.Minerals.")))
{
$EqIdValidation =$false
}
else
{
$EqIdValidation = $true
}
# adds the new key-value pair
$json.TransientStoreApiSettings | Add-Member -Type NoteProperty -Name 'siteName' -Value $SiteName
$json.TransientStoreApiSettings | Add-Member -Type NoteProperty -Name 'EquipmentPhysicalIdentifier' -Value $EquipmentPhysicalIdentifier
#$json.TransientStoreApiSettings | Add-Member -Type NoteProperty -Name 'merlinFilePath' -Value $propValue2
# convers the object back to JSON
$json | ConvertTo-Json | Set-Content $jsonfile