I have the below snippet of code that is supposed to give the user (myself) a YesNo box. If I select Yes, it assigns a value to a variable ($Category). If I select No, it is supposed to start the IncOrRitm function, which I then select from two radio buttons. Each button has a variable assigned to it, with a value to for that variable. If No was selected, the value for the variable assigned to whichever radio button I select should be assigned to the $Category variable.
The logic is this:
Correct category?
Yes -> $Category = Yes
No -> What should ticket have been?
Incident -> $Category = Incident
RITM -> $Category = RITM
However, only the "Yes" part of this code works. I am not sure if I am missing something, or if the function is nested incorrectly, or what....
# is the ticket correctly listed as an incident/ritm
Add-Type -AssemblyName PresentationCore,PresentationFramework
$ButtonType = [System.Windows.MessageBoxButton]::YesNo
$MessageTitle = "Incident or RITM"
$MessageBody = "Was the category correctly selected?"
$IncOrRITM = [System.Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType)
if ($IncOrRITM -eq "Yes")
{
$Category = "Correct"
}
elseif ($IncOrRITM -eq "No")
{
function IncOrRITM{
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$Form = New-Object System.Windows.Forms.Form
$Form.width = 300
$Form.height = 170
$Form.Text = ”What Should The Ticket Have Been?"
$Font = New-Object System.Drawing.Font("Verdana",11)
$Form.Font = $Font
$MyGroupBox = New-Object System.Windows.Forms.GroupBox
$MyGroupBox.Location = '5,5'
$MyGroupBox.size = '275,65'
$RadioButton1 = New-Object System.Windows.Forms.RadioButton
$RadioButton1.Location = '20,20'
$RadioButton1.size = '90,30'
$RadioButton1.Checked = $false
$RadioButton1.Text = "Incident"
$RB1 = "Incorrect - Should be an Incident"
$RadioButton2 = New-Object System.Windows.Forms.RadioButton
$RadioButton2.Location = '150,20'
$RadioButton2.size = '90,30'
$RadioButton2.Checked = $false
$RadioButton2.Text = "RITM"
$RB2 = "Incorrect - Should be an RITM"
$OKButton = new-object System.Windows.Forms.Button
$OKButton.Location = '10,90'
$OKButton.Size = '90,35'
$OKButton.Text = 'OK'
$OKButton.DialogResult=[System.Windows.Forms.DialogResult]::OK
$CancelButton = new-object System.Windows.Forms.Button
$CancelButton.Location = '180,90'
$CancelButton.Size = '90,35'
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$CancelButton.DialogResult=[System.Windows.Forms.DialogResult]::Cancel
$form.Controls.AddRange(@($MyGroupBox,$OKButton,$CancelButton))
$MyGroupBox.Controls.AddRange(@($Radiobutton1,$RadioButton2))
$form.AcceptButton = $OKButton
$form.CancelButton = $CancelButton
$form.Add_Shown({$form.Activate()})
$dialogResult = $form.ShowDialog()
if ($DialogResult -eq "OK")
{
if ($RadioButton1.Checked){$Category = $RB1}
if ($RadioButton2.Checked){$Category = $RB2}
}
elseif ($DialogResult -eq "Cancel")
{
break
}
}
IncOrRITM
}