[RESOLVED] Confused over how to implement some IF/Then logic
I'm sure this should be easy but I'm having trouble getting my head around it. I shall try to explain what I need as best I can.
I have a string called SoftwareGroupName. If that string is empty, I need to run some code that logs a call in our Helpdesk. So far, so simple.
I then check two other variables, AuthorityLevel and InstallType. If the AuthorityLevel is anything other than "OnRequest" then a call is logged in the Helpdesk System. Again, so far, so simple.
The problem occurs when the AuthorityLevel is "OnRequest". At this point, the application should again log a call in the Helpdesk Call with a status of "Resolved" as well as add the user to the relevant group in Active Directory.
What I need to be able to do is, effectively, say "If the AuthorityLevel is OnRequest and SoftwareGroupName is not empty then go ahead and create the call and update the group. However, if softwaregroupname is empty then DON'T even try and update the group and create a call with a different status (e.g. Assigned).
Here's what I'm doing so far. But it seems wrong to have to check that SoftwareGroupName is empty twice.
Code:
Private Sub CreateCall
Dim dic As New Dictionary(Of String, String)
If Not rowSoftware Is Nothing Then
dic.Add("[#STATUS#]", "New")
dic.Add("[#DESCRIPTION#]", description)
dic.Add("[#USERID#]", UserID)
dic.Add("[#USERNAME#]", UserFullName)
dic.Add("[#GROUP#]", "G-ITSD-1st")
dic.Add("[#SOLSUMMARY#]", "")
dic.Add("[#SOLDETAILS#]", "")
description = UserID + " requests installation of " + _
rowSoftware.Description + " on " + Softwarename _
+ ". Business Justification=" + Justification
description = description.Replace(Environment.NewLine, " ")
Try
softwareGroupName = rowSoftware.DistributionGroupName.ToString()
Catch ex As Exception
End Try
If softwareGroupName = String.Empty Then
TraceDebug("No groupname for package : " + SoftwareID + " software->" + rowSoftware.Description)
If rowSoftware.TYPE = TypeEnum.Package.ToString() Then
description = "Please create a new Package group for " + rowSoftware.Description
Else
description = "Please create a new Manual Install group for " + rowSoftware.Description
End If
description = description.Replace(Environment.NewLine, " ")
dic.Add("[#SUMMARY#]", "Missing distribution group for " + rowSoftware.Description)
dic.Add("[#DESCRIPTION#]", description)
dic.Add("[#USERID#]", "xxx")
dic.Add("[#USERNAME#]", "xxxx")
dic.Add("[#GROUP#]", "xxxx")
mail_adapter.SendMailToRemedy("incident", dic)
Else
TraceDebug("AD group Name = " + rowSoftware.DistributionGroupName)
TraceDebug("Authority Level = " + rowSoftware.AuthorityLevel.ToString())
Select Case rowSoftware.AuthorityLevel
Case AuthorizationLevelEnum.OnRequest
If Not softwareGroupName = String.Empty Then
TraceDebug("AddUserToGroup->" + PCOwner + " in " + softwareGroupName)
Dim ad_adapter As New AD_Adapter
ad_adapter.AddUserToGroup(PCOwner, softwareGroupName)
If rowSoftware.TYPE = TypeEnum.Package.ToString() Then
TraceDebug("Create email Package Request for -> " + UserID + " and software group " + softwareGroupName)
dic.Add("[#SUMMARY#]", "Automated software request for " + rowSoftware.Description)
dic("[#STATUS#]") = "Resolved"
dic("[#SOLSUMMARY#]") = "User added to " + softwareGroupName
dic("[#SOLDETAILS#]") = "User added to " + softwareGroupName
Else
TraceDebug("Create email Manual Request for -> " + UserID + " and software group " + softwareGroupName)
dic.Add("[#SUMMARY#]", "Manual installation software request for " + rowSoftware.Description)
mail_adapter.SendMailToRemedy("change", dic)
End If
Else
TraceDebug("Create 'Add user to group after creation' call for -> " + UserID + " and software group " + softwareGroupName)
dic.Add("[#SUMMARY#]", "Add user to AD group for " + softwareGroupName + " when created by G-COE")
End If
mail_adapter.SendMailToRemedy("change", dic)
Case Else 'Need Approval
'Remedy Mail
TraceDebug("Create email Manual Request for -> " + UserID + " and software group " + softwareGroupName)
dic.Add("[#SUMMARY#]", "Approval required software request for " + rowSoftware.Description)
mail_adapter.SendMailToRemedy("change", dic)
End Select
End If
Else
TraceDebug("ERROR! No row software found for package : " + SoftwareID)
End If
End Sub
Re: Confused over how to implement some IF/Then logic
so....
Code:
If the AuthorityLevel = "OnRequest" andalso SoftwareGroupName <> "" then
go ahead and create the call and update the group.
ElseIf SofwareGroupName = "" Then
DON'T even try and update the group and create a call with a different status
Else
???? do yet another action
End If
does that help?
-tg
Re: Confused over how to implement some IF/Then logic
Yes, I figured it was going to be using AndAlso. I shall try that, thanks
Re: Confused over how to implement some IF/Then logic
Well, that's simplified matters considerably!
Thank you for clearing that up.
Re: [RESOLVED] Confused over how to implement some IF/Then logic
well, the logic was in your question... it just needed to be exrapolated... infact, that's how I built it.... I took the question and changed it into the if/then needed.
-tg